Macro XDIR (from Fraktal SAS Programming)
Inhaltsverzeichnis
What it does
This SAS Macro reads entries from a specified OS directory and writes results to the SAS LOG screen.
- When no directory is specified, a pop-up window is defined and opened to ask the user for the directory name.
Annotated Code
Code executed | Function performed |
---|---|
|
Start macro definition with name and positional parameter xpath. |
|
Define branch when parameter xpath is not supplied. |
|
Start definition of pop-up window. |
|
Specify position and size of window. |
|
Specify constant text shown, parameter name to be populated and attributes. |
; |
Terminate pop-up window definition statement. |
|
Open pop-up window. |
|
Finalize branch definition for empty parameter xpath. |
|
Define text data stream with type pipe and logical record length. |
|
Initiate data step run group. |
|
Specify length in byte for character field entry. |
|
Open text data stream path. |
|
Specify structure of data stream path. |
|
Write value from field entry to the SAS LOG screen. |
|
Terminate data step run group. |
|
Revoke definition of text data stream. |
|
END macro definition with name |
How it is done
- Upon initialization the presence of the parameter "xpath" is checked.
- If not present, a pop-up window is defined and popped-up to ask the user for the path.
- The path is then used to create a text data file reference of type pipe.
- The created fileref is then read with an appropriate input statement.
- No dataset is created by using dummy dataset name _NULL_.
- Each text line input is directly output to the log screen as expected.
Special Effects
Generally, SAS is expecting fixed record length data when reading from a text data source. As is the case in our example here, this condition is not met. When reading varying record length data, SAS needs information about the particular record length. This is obtained by using the "length =" option in the infile statement. The variable named after the "=" - sign will hold the length of each line ready for use by the "varying" format in the input statement.
More Special Effects
If you prefer working with interactive tools instead of rough batch runs, then try a slightly modified version of this macro.