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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

12 REPLIES 12
Ksharp
Super User

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

Bensansing
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Bensansing
Calcite | Level 5

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!

data_null__
Jade | Level 19

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. 

Bensansing
Calcite | Level 5

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

data_null__
Jade | Level 19

Did you remove the $sign?

Bensansing
Calcite | Level 5

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"

data_null__
Jade | Level 19

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

data_null__
Jade | Level 19

shell command EVAL might fix it

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

Tom
Super User Tom
Super User

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"


Bensansing
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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