BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I am using the following code into a ksh file.  I am able to get the first parameter but not the second.

Does someone know how to do it  (see my sas code below).

 

#!/bin/ksh

orderdate=$1
env=$2

echo "This is environment variable read / imported in test2.ksh" $env
echo "This is orderdate variable read / imported in test2.ksh" $orderdate

nohup sas -sysparm $orderdate $env /folder_1881/test3.sas &

 

/*SAS program: test.sas*/


%put =========> &SYSPARM;

%let orderdate = %scan(&sysparm,1);
%let env = %scan(&sysparm,2);


%put &=orderdate;
%put &=env;


1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Try some quotes.  You might also try SYSGET(orderdate); but I'm not sure if the shell variables are available when SAS runs.

 

nohup sas -sysparm "$orderdate $env" /folder_1881/test3.sas &

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

Try some quotes.  You might also try SYSGET(orderdate); but I'm not sure if the shell variables are available when SAS runs.

 

nohup sas -sysparm "$orderdate $env" /folder_1881/test3.sas &
alepage
Barite | Level 11
Thank you for the information. it works well. But I have another issue. When I am calling the khs file at first, the call could be like that.

/.../test.ksh 20220809 8
or
/.../test.ksh 20220829
or
/.../test.ksh 8

Also please note that I a am using a scan function to read each part of the sysparm.

So, in the first call, the orderdate and the environment variables are provided and are read.
in the second call, the orderdate is provided but not the environment value. Despite that, the scan function read properly the orderdate and the enviroment variable is empty is fine.

But I have an issue when the orderdate is blank. It attribute the environment value to the orderdate variable so orderdate=8 and env= is blank and what i want is orderdate blank and env=8.

Is there a way to overcome this issue with the scan function and if so, please provide an example.
Tom
Super User Tom
Super User

Read about how to handle multiple parameters in shell scripts.

https://unix.stackexchange.com/questions/41571/what-is-the-difference-between-and

 

You are not limited to using -sysparm command line option as the method to pass in values.  You can also use the -set command line option to define any number of environment variables which you can retrieve with the SYSGET() or %SYSGET() functions.

 

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/hostunx/p1owmlnzeyxplqn14xlqeqclskd9.htm#p...

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/n106qouqj0hfk5n1wgqpw8iovxy2.htm

 

Example:  Say your Unix shell script called SAS in this way.

# myfile.ksh
sas -set alloptions "$*" -set option1 "$1" -set option2 "$2" myfile.sas

Then the SAS program could retrieve those three values like this:

* myfile.sas ;
%let alloptions=%sysget(alloption);
%let option1=%sysget(option1);
%let option2=%sysget(option2);

So if you called the Unix script like this:

./myfile.ksh A B C D 

The macro variables will be:

ALLOPTIONS=A B C D
OPTION1=A
OPTION2=B

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 519 views
  • 0 likes
  • 3 in conversation