BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RamKumar
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

10 REPLIES 10
Kurt_Bremser
Super User

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.

RamKumar
Fluorite | Level 6

how to set parameters in enviorment variable?

Kurt_Bremser
Super User

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

RamKumar
Fluorite | Level 6

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?

Astounding
PROC Star

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.

Kurt_Bremser
Super User

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

LinusH
Tourmaline | Level 20

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.

Data never sleeps
RamKumar
Fluorite | Level 6

Yes, I would like to parameterized. I guess we can do it via control table but I don't a have full picture.

LinusH
Tourmaline | Level 20

So, get back when you have the full picture Smiley Happy

Data never sleeps
SASKiwi
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 10 replies
  • 2698 views
  • 3 likes
  • 5 in conversation