July 2005 Technical Tip - SAS: Passing parm data from JCL to SAS

If you want to make truly robust SAS programs, you’ll need to master the use of macro variables. And if those SAS programs are being run in a mainframe environment, you’ll want to be able to initialize those variables from your JCL rather than by modifying the SAS source code. This article will show you how to pass parm data from JCL to SAS. This is cool stuff!

In the following program I initialize two JCL symbolic parameters: GREETING is 'HELLO SAS' and NUMBER is 123.45. I then reference those parameters in the EXEC card as PARM='SYSPARM="&GREETING,&NUMBER"'. Note that the PARM value is enclosed in apostrophes whereas the SYSPARM value is enclosed in quotes! This is critical!

//* JOBCARD HERE                                  
//*********************************************                                 
//*  DEMO PASSING PARM DATA FROM JCL TO SAS.  *                                 
//*  BY BILL QUALLS, 02-MAY-2005.             *                                 
//*********************************************                                 
//*                                                                             
//   SET GREETING='HELLO SAS'                                                   
//   SET NUMBER=123.45                                                          
//*                                                                             
//*********************************************                                 
//*  GET PARM, PARSE AND PRINT                *                                 
//*********************************************                                 
//STEP010 EXEC SAS,PARM='SYSPARM="&GREETING,&NUMBER"'                           
//SYSIN    DD *                                                                 
OPTIONS LS=80 ;                                                                 
                                                                                
* PARSE PARM ;                                                                  
DATA _NULL_;                                                                    
   COMMA = INDEX("&SYSPARM",',');                                               
   GREETING = SUBSTR("&SYSPARM",1,COMMA-1);                                     
   NUMBER = SUBSTR("&SYSPARM",COMMA+1);                                         
   CALL SYMPUT('GREETING', TRIM(GREETING));                                     
   CALL SYMPUT('NUMBER', TRIM(NUMBER));                                         
   RUN;                                                                         
                                                                                
* SHOW THE PARSED PARM;                                                         
%PUT GREETING=&GREETING, NUMBER=&NUMBER;                                        
//
Download file here.

I wrote a data step to parse the parm. I have sacrificed conciseness here for readability. Recall that DATA _NULL_ indicates that a SAS dataset is not being created. My parm is comma separated so I use the INDEX function to locate the comma and the SUBSTR function to parse the fields. I then use CALL SYMPUT to create two new macro variables. SAS macro variables are always treated as text; nevertheless, they can be used to assign a value to numeric variable. Sample assignments might include:

MYGREET = "&GREETING";  * Create char field. Quotes required here;
MYNBR = &NUMBER;        * Create a numeric field. No quotes here ;

The output of interest from this SAS program is in the log:

12         * SHOW THE PARSED PARM;           
13         %PUT GREETING=&GREETING, NUMBER=&NUMBER;
GREETING=HELLO SAS, NUMBER=123.45            

Want to know more about SAS? Give us a call! Mainframe or PC, you can count on Caliber Data Training for top quality education.


Go to the articles index. Written by Bill Qualls. Copyright © 2005 by Caliber Data Training 800.938.1222