Macro XAMINE (from Fraktal SAS Programming)
Zur Navigation springen
Zur Suche springen
What it does
This multilevel structured macro combines the simpler ones from above to perform adapted processing of entries from a specified path 'XPATH'. Behavior depends on filter arguments supplied by a segmented parameter 'ETYPE'.
- Segments are limited hardcoded with an underscore ('_').
- 1st segment arguments are processed as SAS program code and copied into the SAS DMS Program Editor.
- 2nd segment arguments are processed as Text and passed to the Wordpad text processor from the MS-Windows accessories collection.
Annotated Code
Code executed | Function performed |
---|---|
|
Start Macro definition with name and positional parameters xpath and etype |
|
Declare global macro variables for communication with called macros |
|
Declare local macro variables |
|
Open access path to listing of OS directory content |
|
Open access path to listing of OS directory content of type 'dir' |
|
Initiate data step to access OS directory content |
|
Declare length of data field 'entry' |
|
Set pointer to access path 'entries' |
|
Read from 'entries' with variable field length |
|
Write count of entries to macro variable 'ne' |
|
Terminate data step |
|
Initiate data step to access OS directories listing |
|
Declare length of data field 'dir' |
|
Set pointer to access path 'dirs' |
|
Read from 'dirs' with variable field length |
|
Terminate data step |
|
Start macro loop to process entries one by one with loop index 'ie' |
|
Initiate data step without creating a dataset |
|
Read row number 'ie' from dataset 'entries' |
|
Write value from read row to macro variable 'entry' with intermediate name processing |
|
Write value from read row to macro variable 'xentry' |
|
Terminate data step |
|
' to the LOG |
|
Write full path and filename to the LOG |
|
Reset value for macro variable 'dir' |
|
Initiate data step without creating a dataset |
|
Read row from dataset 'dirs' with value equal to content of macro variable 'xentry' |
|
Write count of read rows to macro variable 'dir' |
|
Terminate data step |
|
Start macro branch to directory processing |
|
Write string '+----' to the LOG |
|
Use macro 'xdir' to write list of directory content to the LOG |
|
Write string '+----' to the LOG |
|
End macro branch for directory processing |
|
Start macro branch for non-directory processing |
|
Start macro branch for supplied positional parameter 'etype' |
|
Start macro branch for extension of macro variable 'xentry' is found in 2nd delimited segment of macro variable 'etype' |
|
Declare macro variable 'windir' to be global |
|
Call macro 'xset' to populate macro variable 'windir' from OS environment variable 'windir' |
|
Write string '+----' to the LOG |
|
' followed by a message to the LOG |
|
Call external program 'write.exe' to open currently processed file |
|
Write string '+----' to the LOG |
|
End macro branch for extension of macro variable 'xentry' is found in 2nd delimited segment of macro variable 'etype' |
|
Start macro branch for extension of macro variable 'xentry' is found in 1st delimited segment of macro variable 'etype' |
|
Write string '+----' to the LOG |
|
' followed by a message to the LOG |
|
Call macro 'xedit' to open currently processed file in SAS DMS Program Editor |
|
Write string '+----' to the LOG |
|
End macro branch for extension of macro variable 'xentry' is found in 1st delimited segment of macro variable 'etype' |
|
End macro branch for supplied positional parameter 'etype' |
|
End macro branch for non-directory processing |
|
End macro loop to process entries one by one with loop index 'ie' |
|
Invoke the SAS SQL procedure |
|
Delete table 'dirs' |
|
Delete table 'entries' |
|
Terminate the SAS SQL procedure |
|
Close access path to listing of OS directory content |
|
Close access path to listing of OS directory content of type 'dir' |
|
End Macro definition with name |
Special Effects
- The macro makes use of the 'pipe' type file reference. When used appropriately, this returns a list that is instantly generated by an OS command that is given as the statement's argument.
- As an alternate text processing instance the macro uses a SYSTASK statement to call the windows component 'Wordpad'. Since each paticular windows installation uses its own path structure, the macro makes use of the 'windir' environment variable.