Physical File Name
In the business environment it is critical be able to verify the origin of the extracted data. Having the physical file name available during execution can be usefull to create titles, or have the code respond to the availablity of data. Including the physical file name in the SAS log and in titles gives additional documentation that can be helpful in debugging problems.
SAS gives its user the abiltiy to extract information from system control blocks, JFCB and DSCB. These control blocks contain the physical data set name, record length, block size and record format. Using the SAS INFILE statement with RECFM=U LRECL=256 and BLKSIZE=256 is a technique to obtain information about a file. To extract the physical file name can be accomplished with a parameter. The other fields can be extracted using offsets to the control blocks. These fileds can be used to set macro variables to be available thougthout the entire program.
Batch jobs can use JCL to allocate data sets and assign a DDNAME to each data set. The DDNAME is used in SAS code to access the data set. An output title can include the name of the physical data set by typing its name into a title statement. This requires changing the SAS code when a data set in the JCL is changed.
When data from many files are being collected and merge together it becomes harder to keep tract of their origins. Specially when the data sets are changed and the job is re-run.
The filename technique
DATA FILENAME ; FORMAT FILNAM $44. ; INFILE IN FILENAME=FILNAM RECFM=U LRECL=256 BLKSIZE=256 ; DSN=FILNAM ; CALL SYMPUT('FILENAME',SUBSTR(DSN,1,LENGTH(DSN))); RUN ; PROC PRINT ; TITLE1 &FILENAME ;
SAS Fifth Dimension Macro-FILENAME
|DDNAME||The file reference indicator to select the file.|
|FILETYPE||The default File type is adequate for most files.|
File type must be specified for VSAM and ISAM files only.
Currently VSAM and ISAM are the only valid file types that can and must be specified.
|MACNAM||Macro variable name. UP to 8 characters can be specified.|
FILENAME macro invokes the macro SYMPUTC that defines the following naming convention. If 6 or less characters are specified then the name is preceeded and post-scripted with an underscore. If 7 characters is specified then the name is preceeded with an underscore. If 8 characters is specified then the name stays as specified.
SAS program to accomplish Objective 1
Objective 1: Input two flat files and print both files with the physical file name in each title.
//FILENAME EXEC SAS,SASAUTO='SAS Fifth Dimension library' //FILE1 DD DISP=SHR,DSN=YOUR.FIRST.FILE //FILE2 DD DISP=SHR,DSN=YOUR.SECOND.FILE //SASCODE DD DISP=SHR,DSN=MY.SAS.LIBRARY //SYSIN DD * %INCLUDE SASCODE(FILENAME) ; %FILENAME(FILE1) ; DATA FILE1 ; INFILE FILE1 ; INPUT @1 LINE $CHAR132. ; PROC PRINT ; TITLE1 &_FILNAM_ ; %FILENAME(FILE2) ; DATA FILE2 ; INFILE FILE2 ; INPUT @1 LINE $CHAR132. ; PROC PRINT ; TITLE1 &_FILNAM_ ;
%FILENAME(FILE1) ; ------->file1 YOUR.FIRST.FILE DATA FILE1 ; INFILE FILE1 ; INPUT @1 LINE $CHAR132. ; PROC PRINT ; TITLE1 &_FILNAM_ ; TITLE2 &_RECFM_ ; TITLE3 &_LRECL_ ; TITLE4 &_BLKSIZE ; %FILENAME(FILE2) ; ------->file2 YOUR.SECOND.FILE DATA FILE2 ; INFILE FILE2 ; INPUT @1 LINE $CHAR132. ; PROC PRINT ; TITLE1 &_FILNAM_ ; TITLE2 &_RECFM_ ; TITLE3 &_LRECL_ ; TITLE4 &_BLKSIZE ;