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 shell script to trigger a sas program and I wish to redirect to log file.  It does seems to work because I am getting two files. 

 


/.../dapuipa.genjcl.log
/.../dapuipa.genjcl.2023-05-24.log (this one is empty)

 

I would like to have just one file, i.e. /.../dapuipa.genjcl.2023-05-24.log with information in it.

 

What's about this file: /.../dapuipa.genjcl.lst  . Should I redirect and rename this file to avoid an error 11.

 

Please provide corrected script

 

orderdate=$1
ordertime=$2
surveyname=$3
env=$4

#-----------------------------------------------------------
# Cron entries do not execute login scripts.
# Let's run it in the context of our current process
#-----------------------------------------------------------

. /etc/profile

#---------------------------------------------------------------------------------
# Read the parameters and excute the SAS function dapuipa.genjcl.sas
#---------------------------------------------------------------------------------

echo "$orderdate|$ordertime|$name|$env"

sas  -sysparm  "$orderdate|$ordertime|$name|$env" /.../dapuipa.genjcl.sas >> "dapuipa.genjcl.$(date +'%Y-%m-%d').log"

#--------------------
# Exit procedure
#--------------------

exit $?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the -log option to specify the name of the LOG file.  Use the -print option to specify the name of the print file (what SAS now calls the "listing" destination).

 

You might want to use the Unix output re-direction to a third error file to capture any error messages caused by disk outages or whatever.

 

So perhaps something like this:

cd /.../logfolder/ 

echo "$orderdate|$ordertime|$name|$env" >> dapuipa.genjcl.$(date +'%Y-%m-%d').cronlog

sas  -sysparm  "$orderdate|$ordertime|$name|$env" \
     -log dapuipa.genjcl.$(date +'%Y-%m-%d').log \
     -print dapuipa.genjcl.$(date +'%Y-%m-%d').log \
     /.../dapuipa.genjcl.sas \
     2>&1 >> dapuipa.genjcl.$(date +'%Y-%m-%d').cronlog

You should also look at the -set option as it will give you much more flexibility to pass in multiple parameters than the single string the old -sysparm option supports.

sas -set orderdate "$orderdate" -set ordertime "$ordertime" -set name "$name" -set env "$env" ....

Then in the SAS code you can use SYMGET() or %SYMGET() to retrieve the individual environment variable values instead of trying to parse it out of SYSPARM.

%let orderdate=%symget(orderdate);
%let ordertime=%symget(ordertime);
%let name=%symget(name);
%let env=%symget(env);

 

View solution in original post

3 REPLIES 3
ChrisHemedinger
Community Manager

I suggest that you use the -LOG option on the sas command instead of the >> redirect in the shell script.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Tom
Super User Tom
Super User

Use the -log option to specify the name of the LOG file.  Use the -print option to specify the name of the print file (what SAS now calls the "listing" destination).

 

You might want to use the Unix output re-direction to a third error file to capture any error messages caused by disk outages or whatever.

 

So perhaps something like this:

cd /.../logfolder/ 

echo "$orderdate|$ordertime|$name|$env" >> dapuipa.genjcl.$(date +'%Y-%m-%d').cronlog

sas  -sysparm  "$orderdate|$ordertime|$name|$env" \
     -log dapuipa.genjcl.$(date +'%Y-%m-%d').log \
     -print dapuipa.genjcl.$(date +'%Y-%m-%d').log \
     /.../dapuipa.genjcl.sas \
     2>&1 >> dapuipa.genjcl.$(date +'%Y-%m-%d').cronlog

You should also look at the -set option as it will give you much more flexibility to pass in multiple parameters than the single string the old -sysparm option supports.

sas -set orderdate "$orderdate" -set ordertime "$ordertime" -set name "$name" -set env "$env" ....

Then in the SAS code you can use SYMGET() or %SYMGET() to retrieve the individual environment variable values instead of trying to parse it out of SYSPARM.

%let orderdate=%symget(orderdate);
%let ordertime=%symget(ordertime);
%let name=%symget(name);
%let env=%symget(env);

 

alepage
Barite | Level 11
does the print option should end with .lst

ex:

-print dapuipa.genjcl.$(date +'%Y-%m-%d').lst \

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1820 views
  • 2 likes
  • 3 in conversation