BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Longimanus
Quartz | Level 8

I hope somebody can help me with this:  🤞

 

Intro: 

  • I have a table, x_selected_reports,  that during a process will contain program names to be executed. Each row will contain a program name in the column x_rc_rprt_nm.
  • We have three environments/servers: development (Lev1), test (Lev2) and the production environment (Lev3)
  • The path of where this table is found is the problem. If I hard code the environamnt, e.g.: /Lev1/ it all works fine in the call execute command. I like to this to change depending on where it's run. I cannot complete the puzzle how to fix this due to the quotations.  

 

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:  

  • '%include  "/opt/app/sas94/config/Lev1/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";'
  • '%include  "/opt/app/sas94/config/Lev2/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";'
  • '%include  "/opt/app/sas94/config/Lev3/SASApp/SASEnvironment/SASCode/Adhoc/Risk_Reports/'||strip(x_rc_rprt_nm)||'.sas";'

... 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) 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

8 REPLIES 8
Astounding
PROC Star

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';

";
Longimanus
Quartz | Level 8
Omg ... that easy? I will give that a try! Thanx !!! 🙂
Longimanus
Quartz | Level 8

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 

yabwon
Onyx | Level 15

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Longimanus
Quartz | Level 8

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. 

Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2013 views
  • 2 likes
  • 4 in conversation