Hello
I want to run SAS program everyday.
Instead of run it manually everyday I want to run it automatically.
Let's say that everyday the data set "cars" is created and IF the data set exists then need to run the program.
If data set cars doesn't exist then no need to run the program.
What is the way to do it please?
The task is to add the element of automatic running to the code below
Data cars;
set sashelp.cars;
Run;
proc sql;
create table Report1 as
select make,
sum(Invoice) as Total_Invoice format=comma23.,
count(*) as nr_rows format=comma23.,
calculated Total_Invoice/(select sum(Invoice) as Total_Invoice from sashelp.cars Where Origin='Europe') as PCT_Total_Invoice format=percent8.1,
calculated nr_rows/(select count(*) as Total_nr from sashelp.cars Where Origin='Europe') as PCT_nr_rows format=percent8.1
from cars
Where Origin='Europe'
group by make
order by Total_Invoice desc
;
quit;
proc export data=Report1 dbms=xlsx outfile="/usr/local/SAS/SASUsers/LabRet/UserDir/Report1.XLSX" replace;
run;
data _null_;
file sendit email
from="<Bob.Dave@gmail.com>"
to=("<Bob.Dave@gmail.com>")
cc=("<Bob.Dave@gmail.com>","<Bob.Dave@gmail.com>")
subject="Important Document"
importance="High"
attach=("/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars_Report.XLSX"
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
put "Please find attached the file";
put;
put "Thanks!";
run;
That's what you do with scheduling. First thing you need to find out is what schedulers are available to you and what functionality they offer.
Ideally for your case you can use a file trigger event meaning that the arrival of the SAS file is what triggers the scheduler to run your .sas program. Not all schedulers provide such trigger file functionality.
Your other option is a time event that executes your .sas program at a given time each day. You then check in your .sas program if the table exists and only execute the rest of the program if it does.
Thanks,
I will go with second option :execute the .sas program at a given time each day. In .sas program we check if the raw data source table exists and only execute the rest of the program if it does.
May you please show code how to do it?
@Ronein wrote:
Thanks,
I will go with second option :execute the .sas program at a given time each day. In .sas program we check if the raw data source table exists and only execute the rest of the program if it does.
May you please show code how to do it?
Either function EXIST for a SAS table or FEXIST for an external file. Usage examples are in the SAS docu referenced below.
I would like to see please the code for "execute the .sas program at a given time each day.",
The other parts I know how to do
@Ronein wrote:
I would like to see please the code for "execute the .sas program at a given time each day.",
The other parts I know how to do
That's what you do with a scheduler - which is not SAS code. Here the ones that are often available with a SAS installation (except for Platform Suite for SAS (lsf) which doesn't come "automatically" anymore with newer SAS versions). Scheduling in SAS® 9.4, Second Edition
How can I know if the scheduler is installed in my sas?
I run this code to see my sas version
%put short version: &sysver; /* 9.4*/
%put version: &sysvlong4; /*version: 9.04.01M4P11092016*/
%put site #: &syssite; /*site #: 70072655*/
%put cpu: &sysscp &sysscpl; /*cpu: LIN X64 Linux*/
I run this code too to see
proc product_status;run;
Here is the Log
1 The SAS System 08:30 Tuesday, December 27, 2022 1 ;*';*";*/;quit;run; 2 OPTIONS PAGENO=MIN; 3 %LET _CLIENTTASKLABEL='Program (8)'; 4 %LET _CLIENTPROCESSFLOWNAME='Process Flow'; 5 %LET _CLIENTPROJECTPATH=''; 6 %LET _CLIENTPROJECTPATHHOST=''; 7 %LET _CLIENTPROJECTNAME=''; 8 %LET _SASPROGRAMFILE=''; 9 %LET _SASPROGRAMFILEHOST=''; 10 11 ODS _ALL_ CLOSE; 12 OPTIONS DEV=PNG; 13 GOPTIONS XPIXELS=0 YPIXELS=0; 14 FILENAME EGSR TEMP; 15 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR 16 STYLE=HTMLBlue 17 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css") 18 NOGTITLE 19 NOGFOOTNOTE 20 GPATH=&sasworklocation 21 ENCODING=UTF8 22 options(rolap="on") 23 ; NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR 24 25 GOPTIONS ACCESSIBLE; 26 proc product_status;run; For Base SAS Software ... Custom version information: 9.4_M4 Image version information: 9.04.01M4P110916 For SAS/STAT ... Custom version information: 14.2 For SAS/GRAPH ... Custom version information: 9.4_M4 For SAS/ETS ... Custom version information: 14.2 For SAS/FSP ... Custom version information: 9.4_M4 For SAS/OR ... Custom version information: 14.2 For SAS/AF ... Custom version information: 9.4_M4 For SAS/IML ... Custom version information: 14.2 For SAS/CONNECT ... Custom version information: 9.4_M4 For SAS Risk Management ... Custom version information: 6.7 Image version information: 9.04.01M0P110916 For SAS OLAP Server ... Custom version information: 9.4 For SAS LASR Analytic Server ... Custom version information: 2.8 For SAS/ACCESS to Hadoop ... Custom version information: 9.44 For SAS Enterprise Miner ... Custom version information: 14.2 2 The SAS System 08:30 Tuesday, December 27, 2022 For SAS/ACCESS to Postgres ... Custom version information: 9.4_M4 For SAS Integration Technologies ... Custom version information: 9.4_M4 For BIS Common Server Install ... Custom version information: 6.1 Image version information: 9.04.01M0P040616 For SAS Credit Scoring for Banking Server ... Custom version information: 6.1 Image version information: 9.04.01M0P040616 For SAS/Secure 168-bit ... Custom version information: 9.41_M1 For SAS Credit Scoring ... Custom version information: 14.2 For SAS High-Performance Forecasting ... Custom version information: 14.2 For Decision Manager Server ... Custom version information: 3.2 Image version information: 9.04.01M0P110916 For Advanced Programming for LASR Analytic Server ... Custom version information: 2.8 For SAS Visual Analytics Server Components ... Custom version information: 7.3 Image version information: 9.04.01M0P072915 For OpRisk VaR Server ... Custom version information: 6.1_M2 Image version information: 9.04.01M0P042215 For SAS Regulatory Risk Management Server ... Custom version information: 5.4 Image version information: 9.04.01M0P070616 For High Performance Suite ... Custom version information: 2.2_M5 For SAS/ACCESS Interface to DB2 ... Custom version information: 9.4_M2 For SAS/ACCESS Interface to Oracle ... Custom version information: 9.41 For Bus Rules Manager Server ... Custom version information: 3.2 Image version information: 9.04.01M0P110916 For Stress Testing Server ... Custom version information: 2.3 Image version information: 9.04.01M0P110916 For SAS/ACCESS Interface to PC Files ... Custom version information: 9.4_M4 For SAS/ACCESS Interface to ODBC ... Custom version information: 9.4_M4 For SAS/ACCESS Interface to Teradata ... Custom version information: 9.44 For SAS/ACCESS Interface to Microsoft SQL Server ... Custom version information: 9.42 NOTE: PROCEDURE PRODUCT_STATUS used (Total process time): real time 0.04 seconds user cpu time 0.01 seconds system cpu time 0.01 seconds memory 353.62k OS Memory 29348.00k Timestamp 12/27/2022 02:41:10 PM Step Count 101 Switch Count 0 3 The SAS System 08:30 Tuesday, December 27, 2022 Page Faults 0 Page Reclaims 212 Page Swaps 0 Voluntary Context Switches 59 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 27 28 29 GOPTIONS NOACCESSIBLE; 30 %LET _CLIENTTASKLABEL=; 31 %LET _CLIENTPROCESSFLOWNAME=; 32 %LET _CLIENTPROJECTPATH=; 33 %LET _CLIENTPROJECTPATHHOST=; 34 %LET _CLIENTPROJECTNAME=; 35 %LET _SASPROGRAMFILE=; 36 %LET _SASPROGRAMFILEHOST=; 37 38 ;*';*";*/;quit;run; 39 ODS _ALL_ CLOSE; 40 41 42 QUIT; RUN; 43
On Linux, you use the cron daemon to run a program unsupervised at a given time. The program with which you set the entries in your cron table is called crontab. Do a Google search, you'll find lots of entries for how to use it. My preferred way is to have a personal file in my home directory (e.g. ~/crontab.txt) where I keep my entries, and then run crontab crontab.txt from the commandline.
Bases on our conversation which type should I choose?
Do you have a SAS administrator? They will be familiar with your SAS installation's scheduling capabilities and how to set it up. We are flying blind here as we don't know what you have.
I would recommend using SAS Management Console's Schedule Manager. That is a SAS tool that needs to be installed on your PC. Again your SAS administrator should be able to help.
You either are the SAS admin, or you ask the SAS admin. Noone else can assist you with the details of your local SAS setup.
It is one of the jobs of the SAS admin to assist SAS users.
If you have SAS Management Console installed you will always find Schedule Manager as it is not an optional function. I don't understand your reluctance to talk to your SAS administrator as you will make much faster progress getting their help.
Sure, the gentleman is on holiday .....so I wanted to know what is the way to check by myself if "SAS Management Console's Schedule Manage" exists on my SAS...
SAS Management Console is a separate application that you can install from your SAS software depot. Once installed on your PC it should be listed in your SAS Software folder shortcuts, along with any other client SAS applications like Enterprise Guide.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.