May I request someone to shed some lights to create a parameterized job which should run start of each month starting from July 01,2015? I was excepting only the tips, with that I can manage to complete the task.
Thanks in advance for any help.
2) You must use %sysget to transfer the value of the environment variable.
Environment variables in UNIX (and Windows) are set from the commandline (shell). Therefore you don't put them into a SAS configuration file.
Here's my(our) method:
- a specific set of environment variables has been defined by us (SAS admins) and the data center people; one of those is the jobname (SAS program name without the .sas)
- SAS programs to be scheduled are stored in a defined path
- for scheduled jobs, a UNIX script called sasbatch has been created that calls SAS in batch mode, with a specialized config & autoexec
- that sasbatch makes sure that all specified (see above) environment variables are present; if not, they are created with a dummy value
- each job run is individualized with datetime and process number
- the logfile is specified with program name and individulization, so that every run leaves a distinct log
- the sasbatch runs a special SAS program before and after each job in a separate SAS call. This program records every job in a dataset (before with "running", after with return code) and creates a daily HTML page that displays all job runs for that day
- to make programming of scheduled jobs easier, an include called pre-run.sas has been written that does all the %sysget and writes all values into the log, for control purposes
In order to successfully create and run scheduled jobs, you need to acquire knowledge about the underlying operating system (for shell scripting) and the scheduling tools present
Use macro variables in the SAS code for parametrization.
To set those macro variables, you could use the -sysparm commandline option when running a batch job and parse the &SYSPARM automatic macro variable.
Or you can set your parameters in environment variables and use %sysget to retrieve the values.
Or you can set your macro variables from user-defined prompts if you run the jobs manually from EG.
how to set parameters in enviorment variable?
This depends on the operating system.
In UNIX, it is (in a shell script)
export VARNAME=value
(it is common to write environment variables in capitals to easily distinguish them from commands, files etc)
"export" is a keyword that puts the environment variable in the "public" block that is visible to child processes (one of those will be your SAS job).
So, imagine you have a file called /home/user/example.sas:
%let indate=%sysget(INDATE);
proc print data=test;
where date="&indate."d;
run;
now you do (in a shell script):
export INDATE=01jan2015
sas /home/user/example.sas -print /home/user/example.lst
This will create a listing of records with the wanted date in the .lst file
Thanks for the explanation. My understanding is,
1. Create environment variable like, export INDATE=01jan2015 in UNIX box.
2.If I run the SAS code below in UNIX, macro variable will automatically resolved to 01jan2015.
Please advise if I overlook any. Do we need to create a environment variable in SAS configuration file?
Environmental variables are not automatically transferred into macro variables. You need to explicitly use %SYSGET to make that happen.
Also note, many monthly applications try to retrieve data from a previous time period, such as the previous month. You can do that in SAS using the INTNX function. Even if you don't have a macro variable with the beginning date in it, SAS provides the date on which the program runs as a macro variable. For example, consider:
where (intnx('month', "&sysdate9"d, -1) <= date_variable < intnx('month', "&sysdate9"d, 0));
If your program runs on any date in July 2015, it automatically selects values for DATE_VARIABLE that have a June 2015 date.
Good luck.
2) You must use %sysget to transfer the value of the environment variable.
Environment variables in UNIX (and Windows) are set from the commandline (shell). Therefore you don't put them into a SAS configuration file.
Here's my(our) method:
- a specific set of environment variables has been defined by us (SAS admins) and the data center people; one of those is the jobname (SAS program name without the .sas)
- SAS programs to be scheduled are stored in a defined path
- for scheduled jobs, a UNIX script called sasbatch has been created that calls SAS in batch mode, with a specialized config & autoexec
- that sasbatch makes sure that all specified (see above) environment variables are present; if not, they are created with a dummy value
- each job run is individualized with datetime and process number
- the logfile is specified with program name and individulization, so that every run leaves a distinct log
- the sasbatch runs a special SAS program before and after each job in a separate SAS call. This program records every job in a dataset (before with "running", after with return code) and creates a daily HTML page that displays all job runs for that day
- to make programming of scheduled jobs easier, an include called pre-run.sas has been written that does all the %sysget and writes all values into the log, for control purposes
In order to successfully create and run scheduled jobs, you need to acquire knowledge about the underlying operating system (for shell scripting) and the scheduling tools present
Do you really need it to be parameterized?
What parameter(s) do you need, and how will you use them?
A scheduling tool handles the execution time/date.
For a monthly batch, a lookup table could be sufficient.
Yes, I would like to parameterized. I guess we can do it via control table but I don't a have full picture.
So, get back when you have the full picture
What scheduler do you plan to use? If you have the SAS LSF scheduler you can set up your scheduling in SAS Management Console, including parameters which LSF then creates environment variables from. You can then use %SYSGET in your SAS code to read these into macro variables, as has been already mentioned.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.