Macro XSET (from Fraktal SAS Programming): Unterschied zwischen den Versionen

Aus phenixxenia.org
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

Zurück

Übersicht

Vorwärts

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

%MACRO xset(xvar);

Start Macro definition with name and positional parameter xvar

filename path pipe "set" lrecl = 2048;

Open source for text data of type pipe pointing to OS command

data _NULL_;

Start datastep run group

length xvar $256 xval $1024;

Declare variables xvar and xval by length in bytes

infile path dlm = '=';

Utilize data stream from data source path

input xvar $ xval $;

Define structure of data stream path with variables xvar and xval

xvar = upcase(translate(xvar,'_','(-)'));

Remove unwanted characters from variable xvar

%IF %LENGTH(&XVAR.) != 0 %THEN %DO;

Specify condition on macro parameter xvar for using code segment

if trim(xvar) = "%UPCASE(&XVAR.)";

Conditionally executed code

%END;

End condition on macro parameter xvar

call symput(compress(xvar),compress(xval));

Transfer variable values to symbol table

run;

End data step run group

filename path clear;

Close source for text data

%MEND xset;

End Macro definition with name

Zurück

Übersicht

Vorwärts