Macro rXDIR (from Fraktal SAS Programming): Unterschied zwischen den Versionen
Die Seite wurde neu angelegt: „Kategorie:Zazy {{SeitenNavigation1 |hoch=Duck_zazy_com.png |links=xx_left.png |rechts=xx_right.png |übersicht=Macro XDIR (from Fraktal SAS Programming) |z…“ |
KKeine Bearbeitungszusammenfassung |
||
(7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 24: | Zeile 24: | ||
</font> | </font> | ||
| | | | ||
Start macro definition with name and positional parameter ''xpath'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%GLOBAL rpath; | |||
</font> | </font> | ||
| | | | ||
Declare macrovariable ''rpath'' as global | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%LET xpath = ; | |||
</font> | </font> | ||
| | | | ||
Empty macrovariable ''xpath'' | |||
|- | |- | ||
| | | | ||
Zeile 42: | Zeile 45: | ||
</font> | </font> | ||
| | | | ||
Start definition for macro window ''path'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:irow = 20 rows = 14 icolumn = 130 columns = 64 | |||
</font> | </font> | ||
| | | | ||
Set coordinates for macro window ''path'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: #3 @5 "Current Path: &RPATH." | |||
</font> | </font> | ||
| | | | ||
Define 1st output line containing value from macrovariable ''rpath'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: #5 @5 'Enter path: ' xpath 40 attr = blink | |||
</font> | </font> | ||
| | | | ||
Define 2nd output line and field attributes to read macrovariable ''xpath'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
; | ''';''' | ||
</font> | </font> | ||
| | | | ||
End definition of macro window ''path'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%DISPLAY path; | |||
</font> | </font> | ||
| | | | ||
Invoke macro window ''path'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%IF %LENGTH(&XPATH.) = 0 %THEN %GOTO leave; | |||
</font> | </font> | ||
| | | | ||
Branch to label ''leave'' for condition "''null value entered''" | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%LET rpath = &RPATH.&XPATH.\; | |||
</font> | </font> | ||
| | | | ||
Append value from macrovariable ''xpath'' to macrovariable ''rpath'' | |||
|- | |- | ||
| | | | ||
Zeile 90: | Zeile 101: | ||
</font> | </font> | ||
| | | | ||
Create file reference of type ''pipe'' to read entries from directory named in ''rpath'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%PUT ---&RPATH.---; | |||
</font> | </font> | ||
| | | | ||
Output roughly formatted header containing value from ''rpath'' | |||
|- | |- | ||
| | | | ||
Zeile 102: | Zeile 115: | ||
</font> | </font> | ||
| | | | ||
Initiate datastep w/o creating a dataset | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:length entry $256; | |||
</font> | </font> | ||
| | | | ||
Specify field length to read directory entries' names into | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:infile path length = lrecl; | |||
</font> | </font> | ||
| | | | ||
Open data stream from file reference | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:input entry $varying256. lrecl; | |||
</font> | </font> | ||
| | | | ||
Define tokens coming in of varying length with name ''entry'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:put entry; | |||
</font> | </font> | ||
| | | | ||
Instantly write ''entry'' to the LOG screen | |||
|- | |- | ||
| | | | ||
Zeile 132: | Zeile 150: | ||
</font> | </font> | ||
| | | | ||
Terminate the data step | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
; | ;filename path clear; | ||
</font> | </font> | ||
| | | | ||
Close data stream ''path'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%RXDIR(&RPATH.) | |||
</font> | </font> | ||
| | | | ||
Recursively call macro ''rxdir'' with parameter ''rpath'' | |||
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%LEAVE: | |||
</font> | |||
| | |||
Define GOTO label 'leave' | |||
|- | |||
| | |||
<font face="Courier New"> | |||
:%LET rpath = ; | |||
</font> | </font> | ||
| | | | ||
Empty macrovariable ''rpath'' | |||
|- | |- | ||
| | | | ||
Zeile 159: | Zeile 188: | ||
|} | |} | ||
{{SeitenNavigation1 | |||
|hoch=Duck_zazy_com.png | |hoch=Duck_zazy_com.png | ||
|links=xx_left.png | |links=xx_left.png |
Aktuelle Version vom 24. November 2014, 19:05 Uhr
What it does
This SAS Macro provides the function from XDIR in an interactive mode.
- The recursive use of macro invocation keeps the macro "alive" until no further user input is made.
- It might be of some interest to the novice user, how easy it is, to turn a simple "home-grew" function into an interactive tool.
Code executed | Function performed |
---|---|
|
Start macro definition with name and positional parameter xpath |
|
Declare macrovariable rpath as global |
|
Empty macrovariable xpath |
|
Start definition for macro window path |
|
Set coordinates for macro window path |
|
Define 1st output line containing value from macrovariable rpath |
|
Define 2nd output line and field attributes to read macrovariable xpath |
; |
End definition of macro window path |
|
Invoke macro window path |
|
Branch to label leave for condition "null value entered" |
|
Append value from macrovariable xpath to macrovariable rpath |
|
Create file reference of type pipe to read entries from directory named in rpath |
|
Output roughly formatted header containing value from rpath |
|
Initiate datastep w/o creating a dataset |
|
Specify field length to read directory entries' names into |
|
Open data stream from file reference |
|
Define tokens coming in of varying length with name entry |
|
Instantly write entry to the LOG screen |
|
Terminate the data step |
|
Close data stream path |
|
Recursively call macro rxdir with parameter rpath |
|
Define GOTO label 'leave' |
|
Empty macrovariable rpath |
|
END macro definition with name |