Macro XSET (from Fraktal SAS Programming): Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
K |
||
Zeile 35: | Zeile 35: | ||
;data ecotope / view = ecotope; | ;data ecotope / view = ecotope; | ||
</font> | </font> | ||
− | | | + | |Start datastep run group to create a view |
|- | |- | ||
| | | | ||
Zeile 65: | Zeile 65: | ||
;%IF %LENGTH(&XVAR.) != 0 %THEN %DO; | ;%IF %LENGTH(&XVAR.) != 0 %THEN %DO; | ||
</font> | </font> | ||
− | |Specify | + | |Specify branch on macro parameter ''xvar'' for using code segment |
|- | |- | ||
| | | | ||
Zeile 71: | Zeile 71: | ||
:if trim(xvar) = "%UPCASE(&XVAR.)"; | :if trim(xvar) = "%UPCASE(&XVAR.)"; | ||
</font> | </font> | ||
− | | | + | |Restrict properties kept to name in macro parameter ''xvar'' |
|- | |- | ||
| | | | ||
Zeile 77: | Zeile 77: | ||
;%END; | ;%END; | ||
</font> | </font> | ||
− | |End | + | |End branch on macro parameter ''xvar'' |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
;run; | ;run; | ||
− | + | </font> | |
− | | | + | |End data step run group |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
;proc sql noprint; | ;proc sql noprint; | ||
− | + | </font> | |
− | | | + | |Initialize SQL interpreter in silent mode |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:select xvar | :select xvar | ||
− | + | </font> | |
− | | | + | |Query values in data field ''xvar'' |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: into :xvar_l separated by ' ' | : into :xvar_l separated by ' ' | ||
− | + | </font> | |
− | |- | + | |Generate macro variable ''xvar_l'' from blank-separated list-of-values |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: from ecotope | : from ecotope | ||
− | + | </font> | |
− | | | + | |Use data step view ''ecotope'' |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: ; | : ; | ||
− | + | </font> | |
− | | | + | |Trigger immediate query execution |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
;quit; | ;quit; | ||
− | + | </font> | |
− | | | + | |Terminate SQL interpreter |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
:%GLOBAL &XVAR_L.; | :%GLOBAL &XVAR_L.; | ||
+ | </font> | ||
| | | | ||
− | |||
|- | |- | ||
| | | | ||
Zeile 131: | Zeile 131: | ||
;data _NULL_; | ;data _NULL_; | ||
</font> | </font> | ||
− | |Start datastep run group | + | |Start datastep run group without creating a dataset |
|- | |- | ||
| | | | ||
<font face="Courier New"> | <font face="Courier New"> | ||
: set ecotope; | : set ecotope; | ||
+ | </font> | ||
| | | | ||
− | |||
|- | |- | ||
| | | |
Version vom 12. August 2014, 09:26 Uhr
What it does
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 to create a view |
|
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 branch on macro parameter xvar for using code segment |
|
Restrict properties kept to name in macro parameter xvar |
|
End branch on macro parameter xvar |
|
End data step run group |
|
Initialize SQL interpreter in silent mode |
|
Query values in data field xvar |
|
Generate macro variable xvar_l from blank-separated list-of-values |
|
Use data step view ecotope |
|
Trigger immediate query execution |
|
Terminate SQL interpreter |
|
|
|
Start datastep run group without creating a dataset |
|
|
|
Transfer variable values to symbol table |
|
End data step run group |
|
Close source for text data |
|
End Macro definition with name |
How it is done
- The Macro first defines the OS command "SET" as text data source (SAS file reference) of type "PIPE" that delivers a dynamic two-column matrix with delimiter "=" upon reference to the fileref.
- This fileref is then used to dynamically "populate" a "data step view" that serves as data source for subsequent processing.
- From the left side of the matrix accessed the SQL procedure obtains the names of the OS environment variables and stores them as blank-separated list into a macro variable for use later on.
- Finally a data step with name "_NULL_" is used to write the two-variable dataset delivered by the data step view into the global symbol table.