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

I'm working in windows, and some other program will start a batch SAS job by running a command like:

  sas.exe -sysin "d:\someprogram.sas" -log "d:\logs\mylog.log"  [...]

 

I have two questions:

1. From inside the SAS job, is there a way I can find the full command string that was used to start SAS?  I don't see it in a macro variable. Perhaps it's available in an environment variable somewhere?

 

2. From inside the SAS job, is there a way I can find the value that was passed for the -log argument?  I want to be able to scan the log for errors etc.  I want to allow the program that calls SAS to decide where the log should go, so they can pass any valid location in the -log parameter and the SAS code will know where the log is.

 

If it's not possible, I can think about some workarounds (e.g. add -SYSPARM to the command that starts SAS, and use it to pass the log location). 

 

Thanks,

--Q.

 

 

 

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
1 ACCEPTED SOLUTION

Accepted Solutions
danielduval0
SAS Employee

Quentin,

 

1. I do not believe that from inside the SAS job you are able to find the command string that was used to start SAS. I could be wrong, but I am not aware that this is possible. 

 

2. To tell the program to place the SAS Log in a file, use the following command in the Batch file: 

 

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "C:\Users\<yourUserName>\Documents\ ... PROGRAM.sas" -LOG "C:\Users\<yourUserName>\Documents\ ... PROGRAM.log" -PRINT "C:\Users\<yourUserName>\Documents\ ... PROGRAM.lst" -ICON -NOSPLASH

 

The above text should all be one one line of your Batch file. The bold text indicates this is where you should place the location of your log files. Also, if you are using an ODS statement in your SAS Program be sure to use an ODS Listing statement as well, with the desired location of your log file:

 

ods listing gpath="C:\Users\<yourUserName>\Documents\ ... ";

 

This should allow you to print a log file and any graphs or tables that you have created to a file location using a Batch command. Let me know if you have any questions!

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

View solution in original post

5 REPLIES 5
Quentin
Super User

Looks like for part two, I can just use:

%put %sysfunc(getoption(log));

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
danielduval0
SAS Employee

Quentin,

 

1. I do not believe that from inside the SAS job you are able to find the command string that was used to start SAS. I could be wrong, but I am not aware that this is possible. 

 

2. To tell the program to place the SAS Log in a file, use the following command in the Batch file: 

 

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "C:\Users\<yourUserName>\Documents\ ... PROGRAM.sas" -LOG "C:\Users\<yourUserName>\Documents\ ... PROGRAM.log" -PRINT "C:\Users\<yourUserName>\Documents\ ... PROGRAM.lst" -ICON -NOSPLASH

 

The above text should all be one one line of your Batch file. The bold text indicates this is where you should place the location of your log files. Also, if you are using an ODS statement in your SAS Program be sure to use an ODS Listing statement as well, with the desired location of your log file:

 

ods listing gpath="C:\Users\<yourUserName>\Documents\ ... ";

 

This should allow you to print a log file and any graphs or tables that you have created to a file location using a Batch command. Let me know if you have any questions!

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

Quentin
Super User

Thanks @danielduval0.  That's a bummer about #1.  I would think maybe someone with fancy windows skills could find a way to get the information back from windows somehow.  Something like using the process ID or whatever of the SAS session to look up that command that started that process.  But maybe it'd be too messy to be worthwhile.

 

Understand how to do #2 to direct the log somewhere.  But in this case, the non-SAS application is allowing the user to specify some of the options that are ultimately used to generate the command to start SAS.  So for example, they will choose where to put the log, and perhaps other options for debugging etc.  At least with %GETOPTION(log) I can get the log location.  But would be nice to be able to get the whole command string.

 

Since  they are generating the command string anyway, I might just ask them to pass the generated command string in -sysparm, assuming they can work out the quote marks.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
SASKiwi
PROC Star

If you wrote a shell script to invoke the batch job, you could assign the SAS command to an environment variable then use the SYSGET function in SAS to read it. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 808 views
  • 3 likes
  • 4 in conversation