Macro XDIR (from Fraktal SAS Programming): Unterschied zwischen den Versionen
K |
K |
||
(16 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
[[Kategorie:Zazy]] | [[Kategorie:Zazy]] | ||
{{SeitenNavigation1 | {{SeitenNavigation1 | ||
− | |hoch= | + | |hoch=call a macro bubble 0.png |
|links=xx_left.png | |links=xx_left.png | ||
|rechts=xx_right.png | |rechts=xx_right.png | ||
|übersicht=Macro Programming (from Fraktal SAS Programming) | |übersicht=Macro Programming (from Fraktal SAS Programming) | ||
− | |zurück=Macro | + | |zurück=Macro XSET (from Fraktal SAS Programming) |
− | |vorwärts=Macro | + | |vorwärts=Macro XEDIT (from Fraktal SAS Programming) |
}} | }} | ||
− | + | == 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 == | |
− | + | ||
− | + | {| class="wikitable" | |
− | + | ! Code executed | |
− | + | ! Function performed | |
− | + | |- | |
− | + | | | |
− | + | <font face="Courier New"> | |
− | + | ;%MACRO xdir(xpath); | |
− | + | </font> | |
+ | |Start macro definition with name and positional parameter ''xpath''. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;%IF %LENGTH(&XPATH.) = 0 %THEN %DO; | ||
+ | </font> | ||
+ | |Define branch when parameter ''xpath'' is not supplied. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;%WINDOW path | ||
+ | </font> | ||
+ | |Start definition of pop-up window. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | : irow = 20 rows = 14 icolumn = 30 columns = 64 | ||
+ | </font> | ||
+ | |Specify position and size of window. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | : #4 @5 'Enter path: ' xpath 40 attr = underline | ||
+ | </font> | ||
+ | |Specify constant text shown, parameter name to be populated and attributes. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ''';''' | ||
+ | </font> | ||
+ | |Terminate pop-up window definition statement. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | :%DISPLAY path; | ||
+ | </font> | ||
+ | |Open pop-up window. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;%END; | ||
+ | </font> | ||
+ | |Finalize branch definition for empty parameter ''xpath''. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;filename path pipe "dir /b ""&XPATH.""" lrecl = 256; | ||
+ | </font> | ||
+ | |Define text data stream with type '''''pipe''''' and logical record length. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;data _NULL_; | ||
+ | </font> | ||
+ | |Initiate data step run group. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | :length entry $256; | ||
+ | </font> | ||
+ | |Specify length in byte for character field ''entry''. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | :infile path length = lrecl; | ||
+ | </font> | ||
+ | |Open text data stream ''path''. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | :input entry $varying256. lrecl; | ||
+ | </font> | ||
+ | |Specify structure of data stream ''path''. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | : put entry; | ||
+ | </font> | ||
+ | |Write value from field ''entry'' to the SAS LOG screen. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;run; | ||
+ | </font> | ||
+ | |Terminate data step run group. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;filename path clear; | ||
+ | </font> | ||
+ | |Revoke definition of text data stream. | ||
+ | |- | ||
+ | | | ||
+ | <font face="Courier New"> | ||
+ | ;%MEND xdir; | ||
+ | </font> | ||
+ | |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 [[Macro rXDIR (from Fraktal SAS Programming)|slightly modified version]] of this macro. | ||
{{SeitenNavigation1 | {{SeitenNavigation1 | ||
− | |hoch= | + | |hoch=call a macro bubble 0.png |
|links=xx_left.png | |links=xx_left.png | ||
|rechts=xx_right.png | |rechts=xx_right.png | ||
|übersicht=Macro Programming (from Fraktal SAS Programming) | |übersicht=Macro Programming (from Fraktal SAS Programming) | ||
− | |zurück=Macro | + | |zurück=Macro XSET (from Fraktal SAS Programming) |
− | |vorwärts=Macro | + | |vorwärts=Macro XEDIT (from Fraktal SAS Programming) |
}} | }} |
Aktuelle Version vom 6. Januar 2016, 18:39 Uhr
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.