Monday, June 9, 2014

Pass data through PARM in SAS. "Build output filenames dynamically through SAS"

Suppose we want to build a SAS output file name which will have filename along with the current date,
Example: FNAME_D040414.CSV or .txt.
In this scenario, we need to pass the file name to SAS through PARM.

//STP10 EXEC SAS,PARM='SYSPARM="&NAME"'
//WORK      DD UNIT=WORK,SPACE=(CYL,(50,50),RLSE), 
//SASLOG    DD SYSOUT=*
//OUTCARD   DD DSN=&&OUTCRD,DISP=(NEW,PASS),
//SYSIN     DD DSN=TEST.SAS.PROGRAM(SAS1)


So here we are passing the data through PARM statement on SAS.

So inside the SAS program we need to use the SCAN keyword to retrieve the parameter passed from the jcl and modify accordingly.
'Check the SCAN syntax for more details in the manuals'

OPTION SORTLIB='';               
TITLE;                           
                                 
DATA _NULL_;                     
  NAME = SCAN(SYSPARM(),1,','); 
  CALL SYMPUT("TNAME", TNAME);   
  LENGTH FN $50;                
  INFILE INPUTDATA FILENAME=FN;   
  FILE OUTCARD NOPRINT NOTITLES;
....

We can use the Date combination along with the parameter passed to build the output .txt or .csv dynamically.

No comments:

Post a Comment