SYSPARM calling shell script variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

SYSPARM calling shell script variable

Hey all,

I have wrote a sas program that takes in two sysparms upd_date and CSV.

I am automating these into autosys and running a shell script to execute my program

nohup sas program.sas -sysparm '$CSV $upd_date' -noterminal

I am wondering if there's anyway that you can read in a shell script defined variable into a sysparm call. Right now I read in my sysparms like so: %LET CSV = %SYSFUNC(TRIM(%QSCAN(&SYSPARM,1,%NRSTR(' '))));

So it is reading them in as a character $CSV and not TRANSACTION (which is what CSV is set to in shell script)

Does anyone have any tips or solutions to this, will this work or should I try a different route.


Accepted Solutions
Solution
‎08-04-2015 11:33 AM
Super User
Super User
Posts: 7,039

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

Use double quotes instead of single quotes in your command line.  The unix shell is not expanding the variable reference and so the literal text '$CSV' will be passed to SAS as the value of SYSPARM macro variable.  To test it just use ECHO command.

Compare:

echo -sysparm '$CSV $upd_date'

to

echo -sysparm "$CSV $upd_date"


View solution in original post


All Replies
Super User
Posts: 10,020

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

%LET CSV = %SYSFUNC(TRIM(%QSCAN(&SYSPARM,1,%STR( ))));

Occasional Contributor
Posts: 7

Re: SYSPARM calling shell script variable

Thanks for the reply, this way is still reading in the macro variables as $CSV in my sas code and not what was defined in the shell script.

CSV=TRANSACTION in shell script. Not sure if it's possible to bring in shell script defined variables into a sysparm command.

Thanks for the input though

Super User
Super User
Posts: 7,942

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

Am not too familiar with your OS syntax, however if the variable needs to be de-referenced then it can't go in quotes as far as I know.  Have you tried:

nohup sas program.sas -sysparm $CSV $upd_date -noterminal


If that doesn't work you may need to wrap in a batch file to echo out the full string.

Occasional Contributor
Posts: 7

Re: SYSPARM calling shell script variable

Yeah that doesn't work either, I also tried concatenating full string to run into one variable which didn't work. I think I will take an approach to wrap in a batch file.

Thanks!

Respected Advisor
Posts: 3,799

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

What happens if you use SYSGET on the values scanned from SYSPARM?  You may also be able to skip this SYSPARM and just use SYSGET in your code. 

Occasional Contributor
Posts: 7

Re: SYSPARM calling shell script variable

Posted in reply to data_null__

I also tried using SYSGET yesterday and wasn't working.. was still showing up as $CSV unfortunately

Respected Advisor
Posts: 3,799

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

Did you remove the $sign?

Occasional Contributor
Posts: 7

Re: SYSPARM calling shell script variable

Posted in reply to data_null__

Keep it as: nohup sas program.sas -sysparm "$CSV $upd_date" -noterminal

The change to double quotes makes it work.

"Macro variable CSV resolves to TRANSACTION"

"Macro variable upd_date resolves to 4"

Respected Advisor
Posts: 3,799

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

I was referring to SYSGET  i.e. sysget('$CSV') vs sysget('CSV');

Respected Advisor
Posts: 3,799

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

shell command EVAL might fix it

eval "nohup sas program.sas -sysparm '$CSV $upd_date' -noterminal"

Solution
‎08-04-2015 11:33 AM
Super User
Super User
Posts: 7,039

Re: SYSPARM calling shell script variable

Posted in reply to Bensansing

Use double quotes instead of single quotes in your command line.  The unix shell is not expanding the variable reference and so the literal text '$CSV' will be passed to SAS as the value of SYSPARM macro variable.  To test it just use ECHO command.

Compare:

echo -sysparm '$CSV $upd_date'

to

echo -sysparm "$CSV $upd_date"


Occasional Contributor
Posts: 7

Re: SYSPARM calling shell script variable

Can't believe I didnt think of that to try, thanks for everyone's input and help! Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 574 views
  • 0 likes
  • 5 in conversation