The data is dynamically generated by executing the system command 'set' via the 'filename pipe' instruction. The source is therefore not a pre-existing file but the standard output of this system command, which lists the session's environment variables.
1 Code Block
FILENAME
Explanation : This instruction associates the fileref '_env2ds' with a 'pipe'. It executes the 'set' system command and captures its standard output so that it can be read as a flat file by SAS.
Copied!
filename _env2ds pipe 'set';
1
filename _env2ds pipe 'set';
2 Code Block
DATA STEP Data
Explanation : This DATA STEP block reads data from the '_env2ds' 'pipe'. For each line read ('input'), it extracts the environment variable name by taking the part before the '=' sign and its value by taking the part after. A condition checks that the value is not empty before assigning it. 'name' and 'value' variables are created with predefined lengths and descriptive labels.
Copied!
data &dsout;\n length name $ 40 value $ 1000;\n infile _env2ds;\n input;\n name=scan(_infile_,1,"=");\n if scan(_infile_,2,"=") NE " " then value=substr(_infile_,index(_infile_,"=")+1);\n label name="Environment Variable Name"\n value="Environment Variable Value"\n ;\nrun;
1
DATA &dsout;
2
LENGTH name $ 40 value $ 1000;
3
INFILE _env2ds;
4
INPUT;
5
name=scan(_infile_,1,"=");
6
IF scan(_infile_,2,"=") NE " "THEN value=substr(_infile_,index(_infile_,"=")+1);
7
label name="Environment Variable Name"
8
value="Environment Variable Value"
9
;
10
RUN;
3 Code Block
FILENAME
Explanation : This instruction frees the '_env2ds' fileref and closes the associated 'pipe', which is good practice for resource cleanup.
Copied!
filename _env2ds clear;
1
filename _env2ds clear;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : This is public domain software. No guarantee as to suitability or accuracy is given or implied. User uses this code entirely at their own risk.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.