Macro XSET (from Fraktal SAS Programming): Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
K |
||
Zeile 18: | Zeile 18: | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;%MACRO xset(xvar); | ;%MACRO xset(xvar); | ||
+ | </font> | ||
|Start Macro definition with name and positional parameter ''xvar'' | |Start Macro definition with name and positional parameter ''xvar'' | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:filename path pipe "set" lrecl = 2048; | :filename path pipe "set" lrecl = 2048; | ||
+ | </font> | ||
|Open source for text data of type ''pipe'' pointing to OS command | |Open source for text data of type ''pipe'' pointing to OS command | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;data _NULL_; | ;data _NULL_; | ||
+ | </font> | ||
|Start datastep run group | |Start datastep run group | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:length xvar $256 xval $1024; | :length xvar $256 xval $1024; | ||
+ | </font> | ||
|Declare variables ''xvar'' and ''xval'' by length in bytes | |Declare variables ''xvar'' and ''xval'' by length in bytes | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:infile path dlm = '='; | :infile path dlm = '='; | ||
+ | </font> | ||
|Utilize data stream from data source ''path'' | |Utilize data stream from data source ''path'' | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:input xvar $ xval $; | :input xvar $ xval $; | ||
+ | </font> | ||
|Define structure of data stream ''path'' with variables xvar and xval | |Define structure of data stream ''path'' with variables xvar and xval | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:xvar = upcase(translate(xvar,'_','(-)')); | :xvar = upcase(translate(xvar,'_','(-)')); | ||
+ | </font> | ||
|Remove unwanted characters from variable ''xvar'' | |Remove unwanted characters from variable ''xvar'' | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;%IF %LENGTH(&XVAR.) != 0 %THEN %DO; | ;%IF %LENGTH(&XVAR.) != 0 %THEN %DO; | ||
+ | </font> | ||
|Specify condition on macro parameter ''xvar'' for using code segment | |Specify condition on macro parameter ''xvar'' for using code segment | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:if trim(xvar) = "%UPCASE(&XVAR.)"; | :if trim(xvar) = "%UPCASE(&XVAR.)"; | ||
+ | </font> | ||
|Conditionally executed code | |Conditionally executed code | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;%END; | ;%END; | ||
+ | </font> | ||
|End condition on macro parameter ''xvar'' | |End condition on macro parameter ''xvar'' | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:call symput(compress(xvar),compress(xval)); | :call symput(compress(xvar),compress(xval)); | ||
+ | </font> | ||
|Transfer variable values to symbol table | |Transfer variable values to symbol table | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;run; | ;run; | ||
+ | </font> | ||
|End data step run group | |End data step run group | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
:filename path clear; | :filename path clear; | ||
+ | </font> | ||
|Close source for text data | |Close source for text data | ||
|- | |- | ||
| | | | ||
+ | <font face="Courier New"> | ||
;%MEND xset; | ;%MEND xset; | ||
+ | </font> | ||
|End Macro definition with name | |End Macro definition with name | ||
|} | |} |
Version vom 7. August 2014, 09:22 Uhr
This SAS Macro transfers the environment from the particular operating system to SAS Macro variables.
- Characters "not appreciated" by SAS are removed from variable values.
- If a specific variable name is supplied, this will be the only one transferred.
Code executed | Function performed |
---|---|
|
Start Macro definition with name and positional parameter xvar |
|
Open source for text data of type pipe pointing to OS command |
|
Start datastep run group |
|
Declare variables xvar and xval by length in bytes |
|
Utilize data stream from data source path |
|
Define structure of data stream path with variables xvar and xval |
|
Remove unwanted characters from variable xvar |
|
Specify condition on macro parameter xvar for using code segment |
|
Conditionally executed code |
|
End condition on macro parameter xvar |
|
Transfer variable values to symbol table |
|
End data step run group |
|
Close source for text data |
|
End Macro definition with name |