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

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(')&param1.%bquote(');
  %let param2 = %bquote(')&param2.%bquote(');
%mend;

  %set_constants;                         /* Set macro variables for environment          */
  %put dates=&param1. &param2.;
  /****************************************************************************************************************************************/
  /** 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=&param1.,param2=&param2. 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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@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=&param1.,param2=&param2."" 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 ".

View solution in original post

9 REPLIES 9
mkeintz
PROC Star

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

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=&param1.,param2=&param2."
 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=&param1.,param2=&param2.""
 simple_run_2.sas
" taskname = simple_run_2
;

 

Tater_Salad
Obsidian | Level 7

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=&param1.,param2=&param2."" simple_run_2.sas'' taskname = simple
_run_2;
Tom
Super User Tom
Super User

@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=&param1.,param2=&param2."" 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.

Ksharp
Super User

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

Tater_Salad
Obsidian | Level 7

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=&param1.,param2=&param2."" 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...

Tom
Super User Tom
Super User

@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=&param1.,param2=&param2."" 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 ".

Tater_Salad
Obsidian | Level 7

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=&param1.,param2=&param2.' 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!

Tom
Super User Tom
Super User

It is pretty basic feature of using macro variables to generate SAS code.  Covered very early in the documentation.

http://support.sas.com/documentation/cdl//en/mcrolref/69726/HTML/default/viewer.htm#n0700fspmubii5n1...

 

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 3552 views
  • 2 likes
  • 4 in conversation