a week ago - last edited a week ago
Does anyone that has batch and SAS experience have any clue why a report would get a different name via a batch call of the program compared to the by hand running of the program where the program name does not change and the code does not change in SAS? ...bad report name is like '_2018.06.08.xls' no quotes, good name 'my_sas_program_name_here_2018.06.08.xls' but without the .sas on the program name and again no quotes.
Example sas code:
%macro fdate(fmt); %global fdate; %global tdate; data _null_; call symput("fdate",left(put("&sysdate9"d,&fmt))); call symput("tdate",left(put(today(),&fmt))); run; %mend fdate; %fdate(yymmddp10.) ; %put &fdate ;%put &tdate ; %Let FName = %SysGet( SAS_EXECFILEPATH ) ; %put &fname; %let sasfile= %sysget(SAS_EXECFILEname); %put &sasfile ; %let odsfile=%qsubstr(&sasfile,1, %length(&sasfile)-4); %put &odsfile; %Let PName = %qsubstr(%sysget(SAS_EXECFILEPATH),1, %length(%sysget(SAS_EXECFILEPATH))-%length(%sysget(SAS_EXECFILEname))) ; %put &pname; %let outputfile=&odsfile._&tdate..xls; %put "&outputfile."; ods Tagsets.ExcelXP path = "&pname." file = "&outputfile." /* ... rest of code here ... */
batch call program:
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
REM echo datestamp: "%datestamp%"
REM echo timestamp: "%timestamp%"
REM echo fullstamp: "%fullstamp%"
IF "%~1"=="" GOTO endparse
IF "%~1"=="Yes" "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "c:\test1.sas" -log "c:\test1%fullstamp%.log" -PRINT "c:\test1%fullstamp%.lst"
echo "You did not pass correct parameter, quiting now"
rem Make sure this echo is sent to the same log as the job log goes to above!
echo "You did not pass correct parameter, quiting now" >> c:\test1%fullstamp%.log
ECHO "DONE, processing batch call of SAS program test1.sas" >> c:\test1%fullstamp%.log
To be clear this is not the name of the program but a representative example from the source*. Both the most basic sample from the source and my variation both do the something in batch (both dropping the sas program name) and by hand it is still working as it always has producing an xls report like my_program_name_date_stamp.xls
*source example came from: https://blogs.sas.com/content/sgf/2013/08/14/four-ways-to-schedule-sas-tasks/#comment-390629
Also my batch is not 100% perfected yet but at least does not run if operator does not pass it a Yes option that I want since my program run time is 4 Hours ...logging to be fixed later. 8)
a week ago
It looks like you are trying to name the report after the name of the file that you are editing.
%Let FName = %SysGet( SAS_EXECFILEPATH ) ;
But when you submit the file in batch there is no SAS editor involved.
You could ask SAS what program it is running instead.
%let path = %sysfunc(getoption(sysin));
a week ago
a week ago
It is the EDITOR that is setting the environment variable you are looking for in your original program.
You can sort-of use that when running interactively. As long as you have saved the program somewhere before you submit the code you have open in the editor.
The SYSIN option is the name of the file you told SAS to run when you started SAS. So if you just open SAS interactively it will of course be empty since that is what you told it!
You could just ask the user to TELL you what filename to use for the report. Perhaps by setting a macro variable or using a command line option to set a macro variable.
But if you want to make the program guess at what filename the user wants then your program will need to work a little harder to able to work in both environments.
a week ago
You are setting a lot of environment variables (datestamp, timestamp, etc) in the program that is calling SAS.
Did you try setting a value for SAS_EXECFILEPATH in that code? Then it might exist for your current code to find.