- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 &
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 &
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/.../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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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://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