BookmarkSubscribeRSS Feed
Morfasio
Calcite | Level 5

Hello folks,

I am a very beginner at SAS coding. I want to automate part of a manual task my team has to execute weekly and was suggested to try my hand on SAS. The language seems easy to use and I was able to create a working code. The problem is that we have 200+ systems to run the task and I am having a very hard time to "universalize" the code so we can use only one source for all systems.

 

The idea is to run the following JCL:

//SASREPRT EXEC SAS
.
.
.
//SYSIN DD DISP=SHR,DSN=MYHLQ.RT&&AVP(SASCODE)

The 'RT&&' is a placeholder for the identification the user will have to manually enter each time this job is submitted.

 

This is the part of the SASCODE that reads from the LIST and, after some parsing, it will confirm the jobnames and separate them into 3 datasets:

/*--------------------------------------------------------------------------------------------------------------------------
Purpose:
This DATA step splits the merged job_summary dataset into three separate datasets based on the jobname prefix.

Execution Details:
- Each record from job_summary is evaluated using the substr() function.
- Jobs with jobnames starting with:
- 'RT&&0' are categorized as RIP jobs. The output is sent to dataset rip
- 'RT&&G' are categorized as SysGen jobs. The output is sent to dataset sysgen
- 'RT&&MN' are categorized as Maintenance jobs. The output is sent to dataset maint
- Each matching record is written to its respective dataset using output.

Assumptions:
- Jobname prefixes are consistent and meaningful for classification.
- Only one category applies per job (no overlaps).
--------------------------------------------------------------------------------------------------------------------------*/
data rip sysgen maint;
set job_summary;

if substr(jobname, 1, 5) = 'RT&&0' then output rip;
else if substr(jobname, 1, 5) = 'RT&&G' then output sysgen;
else if substr(jobname, 1, 6) = 'RT&&MN' then output maint;
run;

Is there anyway to pass a PARM on the JCL that would dynamically change the RT&& inside SASCODE for that specific run?

 

Example: User edits the SASREPRT and change RT&& to ABCD. When the job is submitted, the RT&& is dynamically changed in the SASCODE as well. For this to be universal and reusable, SASCODE would have to remain with RT&& after the job is executed.

 

Thanks in advance,

Fábio "Morfasio" Silva

3 REPLIES 3
Tom
Super User Tom
Super User

Haven't used JCL in over 20 years, but SAS has had major enhancements in that time so perhaps you could use SAS code to do what you want?

 

For example can you use the FILENAME= option on an INFILE statement to figure out want the DSN= value was in the JCL DD statement?

 

Morfasio
Calcite | Level 5

Hello Tom, thank you for the reply. And sorry for the delay in getting back to you.

 

I've tried your suggestion but it didn't work, the value was not replaced.

 

I was checking with my colleagues from the performance team (they run reports for virtually everything here) and was told about a library full with all sort of SAS source codes. I've found a code which have the variable defined and the calling is defined in a way I didn't see previously in a JCL.

 

This is the update to my SAS:

data _null_;
    call symput('IMSID',' '); /* Initialize IMSID macro variable */

data _null_;
    infile setup missover; /* Read from SETUP DD */
    input @1 check $1. @;
    if check='*' then do; input; return; end; /* Skip comment lines */
    input @1 text $14.;
    if text=: 'IMSID=' then do;
        text=substr(text,7,4); /* Extract IMSID value */
        call symput('IMSID',text); /* Set macro variable */
    end;
run;

And in the JCL I had to add a SETUP DD card right before the SYSIN:

//SETUP    DD *
*IMSID=  IDENTIFIES THE IMS SYSTEM ID
 IMSID=ABCD

It worked and created the report I wanted. As today is Friday and we are too close to the "happy hour", I'll resume the tests next week. 

Once again, thanks for the suggestion. Have a nice weekend.

 

Regards,
Fábio "Morfasio" Silva

 

ballardw
Super User

I think this https://www.lexjansen.com/nesug/nesug07/po/po13.pdf may get you started.

 

Bascially the idea is using a SAS Macro variable, the bits in SAS that look like &YR1 and &YR2 and then supply the values on a JCL RUN statement.

 

Note that you will want to look up the rules involved in valid SAS Macro variables (reference starts with & followed by letters, digits or _ character ) and that they will only resolve inside double quotes if the value needs to have quotes when used. 

So instead of RT&&0 you might use a macro variable &RT that would be defined to have the value ABCD. To suffix the value with a 0 you would use &RT.0 in the SAS code as the . tells SAS where the end of the macro variable name is so doesn't go looking for a longer variable name.

 

So this code:

if substr(jobname, 1, 5) = 'RT&&0' then output rip;
else if substr(jobname, 1, 5) = 'RT&&G' then output sysgen;
else if substr(jobname, 1, 6) = 'RT&&MN' then output maint;
run;

Might be come

if substr(jobname, 1, 5) = "&RT.0" then output rip;
else if substr(jobname, 1, 5) = "&RT.G" then output sysgen;
else if substr(jobname, 1, 6) = "&RT.MN" then output maint;
run;

 And the call might look something like

//RUN1 EXEC YOURPROG,RT=ABCD

In my case, I haven't written a JCL SAS program since 1991 so made a guess for a google search using SAS JCL PARMBUFF (as parmbuff is one of the things I vaguely remembered using related to this)

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 168 views
  • 0 likes
  • 3 in conversation