- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hi, i am quite new in SAS. I have found the below code in a SAS paper and try to apply it. My issue is i have problem with access to different libraries and therefore the "file" and "%inc" does not work for me.
I am trying to find a way to re-write the below code in one SAS program to avoid the "file" line and then the "%inc" or the file/%inc to be in my current process flow
Is there any way to do it ?
data _NULL_; set PSI.endpoints end=last; file "&PSILibrary\decileSample1.sas"; if _N_ = 1 then put " select;"; put " when (BinVar le " maxVar ") decile = " decile ";" ; if last then do ; put " otherwise decile = " decile ";" ; put "end;"; call symput('maxbin',decile); end; run; data PSI.PSISample2; set PSI.PSISample2; %inc "&PSILibrary\decileSample1.sas" / source; If BinVar=. Then decile=&maxbin; run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The first step in this code generates SAS code (text) that gets written to an external file as text. I've amended the syntax so this code gets written to a dynamically created file in SAS WORK (and only exists as long as your SAS session exists).
The second data step then %includes this text file (that contains SAS syntax) and executes it.
I've also changed option source to source2 in the %include statement. This will write to the SAS log the generated code that gets executed.
libname psi <path to the folder where table endpoints exists>;
filename codegen temp;
data _null_;
set psi.endpoints end=last;
file codegen;
if _n_ = 1 then put " select;";
put " when (binvar le " maxvar ") decile = " decile ";";
if last then
do;
put " otherwise decile = " decile ";";
put "end;";
call symput('maxbin',decile);
end;
run;
data psi.psisample2;
set psi.psisample2;
%include codegen / source;
if binvar=. then decile=&maxbin;
run;
You will still need source table psi.endpoint
and you will need to define a libname psi <path>; that points to the directory where this table resides.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The first step in this code generates SAS code (text) that gets written to an external file as text. I've amended the syntax so this code gets written to a dynamically created file in SAS WORK (and only exists as long as your SAS session exists).
The second data step then %includes this text file (that contains SAS syntax) and executes it.
I've also changed option source to source2 in the %include statement. This will write to the SAS log the generated code that gets executed.
libname psi <path to the folder where table endpoints exists>;
filename codegen temp;
data _null_;
set psi.endpoints end=last;
file codegen;
if _n_ = 1 then put " select;";
put " when (binvar le " maxvar ") decile = " decile ";";
if last then
do;
put " otherwise decile = " decile ";";
put "end;";
call symput('maxbin',decile);
end;
run;
data psi.psisample2;
set psi.psisample2;
%include codegen / source;
if binvar=. then decile=&maxbin;
run;
You will still need source table psi.endpoint
and you will need to define a libname psi <path>; that points to the directory where this table resides.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content