I hope somebody can help me with this: 🤞
Intro:
This works:
data _null_;
set x_selected_reports;
Execcode = '
%include "/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";
';
call execute(execcode);
run;
This does not work (of course it doesn't but you can see what I want to do):
%let Levx=%sysget(LEVX);
data _null_;
set x_selected_reports;
Execcode = '
%include "/opt/app/sas94/config/&Levx./SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";
';
call execute(execcode);
run;
In other words: HOW do I get Execcode to be:
... depending on the environment.
I haven't decoded the issue with ''s and "'s in a text sting that again has to be in quotes, etc. etc.
I hope somebody likes to give it a try. 🙏
Cheers!
Menno (Copenhagen - DK)
Why not to add variable with env. name, e.g. x_Level and do it like this:
Execcode = '
%include "/opt/app/sas94/config/' !! strip(x_Level) !! '/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/' || strip(x_rc_rprt_nm) || '.sas";
';
?
Bart
Macro variables don't resolve within single quotes. You would need to swap the single vs. double quotes, from this:
Execcode = '
%include "/opt/app/sas94/config/&Levx./SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";
';
to this so that double quotes are outermost:
Execcode = "
%include '/opt/app/sas94/config/&Levx./SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/"||strip(x_rc_rprt_nm)||".sas';
";
I can see that the macro variable is "translated" but now there is another issue:
%Let Levx=%sysget(LEVX);
%put &Levx.;
This runs perfect:
data _null_;
set x_selected_reports;
Execcode = '%include "/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";';
call execute(execcode);
run;
Your suggestion does not - although my macro variable is resolved 😊. Something else in the syntax is not working now:
data _null_;
set x_selected_reports;
Execcode = "%include "/opt/app/sas94/config/&Levx./SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";";
call execute(execcode);
run;
LOG of the data step that run as it should:
NOTE: Remote submit to LEV1 commencing.
355 data _null_;
356 set x_selected_reports;
357 Execcode = '%include
357! "/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_
357! rprt_nm)||'.sas";';
358 call execute(execcode);
359 run;
NOTE: There were 2 observations read from the data set WORK.X_SELECTED_REPORTS.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: CALL EXECUTE generated line.
1 + %include
"/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/Test_program_1.sas"
;
NOTE: The data set ANALYS.TEST_OUTPUT_1 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
2 + %include
"/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/Test_program_2.sas"
;
NOTE: The data set ANALYS.TEST_OUTPUT_2 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: Remote submit to LEV1 complete.
LOG of the data step did not run:
378 call execute(execcode);
379 run;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
377:16 377:105 377:134
NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
378:18
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
NOTE: Remote submit to LEV1 complete.
🤔 If somebody can crack this one it would he highly appreciated. In the meantime I will puzzle a little myself.
Cheers!
Menno
Why not to add variable with env. name, e.g. x_Level and do it like this:
Execcode = '
%include "/opt/app/sas94/config/' !! strip(x_Level) !! '/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/' || strip(x_rc_rprt_nm) || '.sas";
';
?
Bart
Do you mean I need to add a new column (containing the environment) to my input table? That is of course an option. Since this is a work-table I could live with that. An option I will try. I still think the other option with the double quotation marks is the best ... when we can make it work of course.
It looks a lot like you are placing your SAS project code into the filesystem you have used to install the SAS software.
You probably will want to keep those two things separate. They are really separate things. They have separate sources, space needs, update cycles, access permission needs, etc.
You can use SAS functions to simplify your code.
Use the CATS() or CATX() function to build the strings. Use the SYSGET() function to retrieve your environment variable. Use the QUOTE() function to enclose the generated filename in quotes.
data _null_;
set x_selected_reports;
call execute(catx(' ','%include'
,quote(cats('/opt/app/sas94/config/'
,sysget('LEVX')
,'/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'
,x_rc_rprt_nm
,'.sas'
))
));
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.