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 $?
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);
I suggest that you use the -LOG option on the sas command instead of the >> redirect in the shell script.
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);
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!
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.
Ready to level-up your skills? Choose your own adventure.