Hi,
We're using SAS 9.xxxx.
I'm on a Linux SYSTEM calling a SAS program from a cronfile.
That SAS program is passing arguments to a SAS program it's calling. I having a hard time passing values from one SAS program to another in this method.
Here are the line from each program.
In the cronfile the line looks like this:
17 * 18 10 * /usr/bin/bash;. ~/.bash_profile; cd /sasdata/mids_output02/rjs;sas -noterminal -rsasuser -batch -log cron_rpts.log -print cron_rpts.lst -sysparm "param1=2500,param2=2" cron_rpts.sas
Here are the effective lines from the program its calling.
%macro set_constants; %global param1 param2; %* Get param1 and param2 from sysparm. sysparmpairs does not deal well with quotes, so quote the dates appropriately; %sysparmpairs(); %let param1 = %bquote(')¶m1.%bquote('); %let param2 = %bquote(')¶m2.%bquote('); %mend; %set_constants; /* Set macro variables for environment */ %put dates=¶m1. ¶m2.; /****************************************************************************************************************************************/ /** Fetch raw pulls of data--transactions (10 min), dnb (33 min), FDIC **/ /****************************************************************************************************************************************/ systask command 'sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm "param1=¶m1.,param2=¶m2. simple_run_2.sas' taskname = sim ple_run_2;
When I look at the log afterwards I see the following:
WARNING: Apparent symbolic reference PARAM1 not resolved. ^L2 The SAS System 20:06 Thursday, October 18, 2018 WARNING: Apparent symbolic reference PARAM2 not resolved. WARNING: Apparent symbolic reference PARAM1 not resolved. WARNING: Apparent symbolic reference PARAM2 not resolved. WARNING: Apparent symbolic reference PARAM1 not resolved.
How do I pass param1 and param2 in that first call to the simple_run_2.sas program so the parameters will pass their values?
@Tater_Salad wrote:
OK but put that solution in the context of this call:
systask command ''sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm ""param1=¶m1.,param2=¶m2."" simple_run_2.sas'' taskname = simple _run_2;As you can see I now have the command with the double quotes as suggested by Tom...
No. You are still using single quote character ' instead of double quote character ".
This worked on our linux system with -sysparm "param1=2500,param2=2":
%put &=sysparm ;
%let %scan(%quote(&sysparm),1,%str(,));
%let %scan(%quote(&sysparm),2,%str(,));
%put _user_;
It says take the 1st comma-separated expression in sysparm (i.e. param1=2500), prefix it with the %LET macro command, and follow it with a semicolon, forming
%let param1=2500;
Doing the same process with the 2nd comma-separated expression produces
%let param2=2;
Macro triggers are not evaluated inside of single quotes.
Change this command:
systask command
'sas
-noterminal
-rsasuser
-batch
-log simple_run_2.log
-print simple_run_2.lst
-sysparm "param1=¶m1.,param2=¶m2."
simple_run_2.sas
' taskname = simple_run_2
;
You could try reversing the quotes so that the outer quotes are double quotes and inner quotes are single quotes.
Or just doubling the inner quotes.
systask command
"sas
-noterminal
-rsasuser
-batch
-log simple_run_2.log
-print simple_run_2.lst
-sysparm ""param1=¶m1.,param2=¶m2.""
simple_run_2.sas
" taskname = simple_run_2
;
I tried it. I did the following and got the same error.
systask command ''sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm ""param1=¶m1.,param2=¶m2."" simple_run_2.sas'' taskname = simple _run_2;
@Tater_Salad wrote:
I tried it. I did the following and got the same error.
systask command ''sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm ""param1=¶m1.,param2=¶m2."" simple_run_2.sas'' taskname = simple _run_2;
You still are using a string enclosed in single quote characters. It is the character used on the outside of the whole quoted value that the macro processor checks to see whether it should evaluate macro triggers or not.
Another way passing parameters is :
-set a "xx" -set b 12
and use the following code to get them.
%let a=%sysget('a');
%let b=%sysget('b');
OK but put that solution in the context of this call:
systask command ''sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm ""param1=¶m1.,param2=¶m2."" simple_run_2.sas'' taskname = simple _run_2;
As you can see I now have the command with the double quotes as suggested by Tom...
@Tater_Salad wrote:
OK but put that solution in the context of this call:
systask command ''sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm ""param1=¶m1.,param2=¶m2."" simple_run_2.sas'' taskname = simple _run_2;As you can see I now have the command with the double quotes as suggested by Tom...
No. You are still using single quote character ' instead of double quote character ".
OK, so you all were right.
Here is the final solution that passed the values all the way through...
systask command "sas -noterminal -rsasuser -batch -log simple_run_2.log -print simple_run_2.lst -sysparm 'param1=¶m1.,param2=¶m2.' simple_run_2.sas" taskname = simple_run_ 2;
The original statement for I used for this in was reversed and that seemed to work for just a command call but apparently if you're going to pass parameters and not just the values you have to reverse the quotes. Where the heck would you look something like this up?
Thanks Again!
It is pretty basic feature of using macro variables to generate SAS code. Covered very early in the documentation.
To resolve a macro variable reference that occurs within a literal string, enclose the string in double quotation marks. Macro variable references that are enclosed in single quotation marks are not resolved.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.