Question: Good Morning!
I want to export a few dataset's to excel using SAS, But I have a few challenges here. Both datasets are unique and which we cannot merge or append.

There are 2 programs that create 2 dataset's each, however, I want to export program1 output datasets(2 datasets) to excel sheet1 and Program2 output dataset'(2 datasets) to Excel sheet2.

I tried using Proc print but it didn't work

```
    ods excel file="&OUTFILE." options(sheet_interval="none"  sheet_name="sheet1");

TITLE 'CLOSED_SR_VOLUMES_BY_PERCENT';
proc print data=CLOSED_SR_VOLUMES_BY_PERCENT;
run;
TITLE 'CLOSED_SR_VOLUMES_BY_VOLUME';
proc print data=CLOSED_SR_VOLUMES_BY_MONTH;
run;

ods excel options(sheet_interval="none" sheet_name="sheet2");
TITLE 'ACTIVE_SR_VOLUMES_BY_VOLUME';
proc print data=SR_VOLUMES_BY_MONTH;
run;
TITLE 'ACTIVE_SR_VOLUMES_BY_PERCENT';
proc print data=SR_VOLUMES_BY_PERCENT;
run;
ods excel close;

```

I am not getting any error but all the datasets are exporting it to one excel sheet instead 2 datasets into sheet1 and another 2 datasets into Sheet2.

Please let me know if there any way to this...

Answer: 
Your method already has a 5 seconds timeout. All you need to do now is to add some kind a loop with 3 repeats. You need a counter of timeouts and a break after successful attempt. Not sure what you want to do when other exceptions happen, added breaks there as well. Following code should do the job:

```
private ConnectionInterface  connectWithTimeout() throws MalformedURLException, Exception {
        int repeatCount = 0;

        ExecutorService executor = Executors.newCachedThreadPool();
        Callable<Object> task = new Callable<Object>() {
            public Object call() throws InterruptedException, MalformedURLException, Exception {
                return connectWithNoTimeout();  //This is the method that takes to long. If this method takes more than 5 seconds, I want to cancel and retry for 3 more times. Then abort completely.
            }
        };

        while (repeatCount < 3){
          Future<Object> future = executor.submit(task);
          try {
              Object result = future.get(5, TimeUnit.SECONDS);
              break;

          } catch (TimeoutException ex) {
            repeatCount++;
            System.out.println( "Timeout Occured");

          } catch (InterruptedException e) {
            System.out.println( " "InterruptedException Occured");
            break; 

          } catch (ExecutionException e) {
              System.out.println( "ExecutionException Occured");
            break;    

          } finally {

              future.cancel(true); // here the method gets canceled. How do I retry it?
          }
        }
        System.out.println( "Connected !!");
        return connectWithNoTimeout();
    }

```
First of all, I'd put the execution of that long command into a new thread so it will not block the Main Thread with the UI etc. 

an approach:

```
Thread thr = new Thread() {
            public void run() {
                boolean error =false;
                boolean success=false;
                int time =0;

                try {
                while(tries<3&&!success){
                    //HERE GOES YOUR METHOD (connectWithNoTimeout(); ?)! Make sure to make the boolean "Success" = true if the connection is established
                    while (!error&&time<3) {
                        time++;
                        Thread.sleep(1000);
                       }
 }

 } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }

                }
        };

```

It's mostly written by hand, you need to make changes, **copy & paste will not work**