0

As mentioned, I dont have any access to scheduling software at work and have a growing list of ongoing reports to keep up with. I'd like to build code or use some sort of functionality within SAS Studio to automate the execution of my code.

Below is what I have put together currently (with a generic report location/name). It will currently run every 5 hours, 8 times so I can check what's happening but would move to running every 24 hours once it works so I would only have to background submit once a week. However, right now, it only looks for the DOM the first time through the loop and then will run the report all 8 times if that criteria was met the first time through. So if it's the 2nd of the month, even if after 4 loops (20 hours) later if it's then the 3rd of the month it is still running the report. I want it to look for the date on each iteration and only execute the code if it's the date given. Thanks!!

%let currentDT = %sysfunc(datetime());
%let currentDate = %sysfunc(today());

data _null_;
wait_sec= '20:00:00't-timepart(datetime());
zzz=sleep(wait_sec,1);
run;

%macro dailyrun (DOM=day(&currentDate));
 %do i=1 %to 8;

        data _null_;
            if &DOM in (2) then do;
                    call execute ('%include "/sasdata/folder/nameofreport.sas";');
                end;
                else; 
            run;


        data _null_;        
            zzz2=sleep(18000000);
            run;
%END;
%mend dailyrun;
%dailyrun() 
Ctine
  • 1
  • Are you on Viya? You can schedule a Viya job to do this. This functionality is built in. – Stu Sztukowski Aug 07 '23 at 17:36
  • @StuSztukowski, unfortunately I'm not on Viya – Ctine Aug 07 '23 at 20:04
  • 1
    Are you on any sort of server? You can schedule SAS code to run with cron or even Windows task scheduler. Otherwise, you're going to have SAS code constantly running which would stop working any time the machine restarts. – Stu Sztukowski Aug 07 '23 at 20:56
  • It's a bad idea to use a SAS session as a scheduler. This job will be running all week, sucking up resources. That said, I think you could change `if &DOM in (2) then do;` to `if day(today()) in (2) then do;` to get what you want. – Quentin Aug 07 '23 at 22:28
  • Using X command to call `schtasks` and this will help you to run a program at specifical time: https://learn.microsoft.com/en-gb/windows-server/administration/windows-commands/schtasks You need different macro logic to custom different command. Good luck. – whymath Aug 08 '23 at 02:10
  • The answers will vary if you're on a server or not, also if SSO is enabled (do you need a different pwd for Studio)? – Reeza Aug 08 '23 at 16:16
  • 1
    Thanks, I'll try some of these ideas. I am on a server and @reeza SSO isn't enabled. When I background submit, it will continue to run even when the machine restarts. – Ctine Aug 08 '23 at 18:41
  • @StuSztukowski Since SAS Studio isn't an installed program can I use Windows Scheduler? If so, can you tell me what to put as the program/script? – Ctine Aug 08 '23 at 18:41
  • SAS Studio is a web interface to the SAS executable on the server. There is a standard way to call the executable and run SAS programs. In a nutshell, you basically run the command `sas myprogram.sas` to run a specific program so long as that program is saved in a physical space on the server. Check out this blog here for information on scheduling. It doesn't mention cron for Unix, but the idea is the same. https://blogs.sas.com/content/sgf/2013/08/14/four-ways-to-schedule-sas-tasks/#:~:text=If%20you%20are%20looking%20for,up%20your%20operating%20system%20scheduler. – Stu Sztukowski Aug 08 '23 at 19:19
  • @StuSztukowski it looks like I dont have permissions to use Windows Scheduler unless I'm actually logged on, so that won't be the best option especially am I'm on vacation. – Ctine Aug 08 '23 at 20:11
  • You'll need to talk with your server admin on how to schedule it. That's their job to do. Give them the script you want to automate and when it should run. They'll handle the rest. – Stu Sztukowski Aug 09 '23 at 18:43
  • That doesn't seem to be an option. They dont have automation available for me which is why I want to code it. I created a second code that the first one points to using the above method and it seems to be working. If it doesn't, I plan to try @Quentin's suggestion. Thanks to all! – Ctine Aug 10 '23 at 20:50

0 Answers0