DATA Step, Macro, Functions and more

SAS batch call results in differnt report name than by hand?

Reply
Frequent Contributor
Posts: 129

SAS batch call results in differnt report name than by hand?

[ Edited ]

Hello all,

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:

@echo OFF
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%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
REM echo datestamp: "%datestamp%"
REM echo timestamp: "%timestamp%"
REM echo fullstamp: "%fullstamp%"
@echo ON
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"
GOTO SKIP_OVER
:endparse
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
Smiley FrustratedKIP_OVER
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)

 TIA  -KJ

Super User
Super User
Posts: 7,929

Re: SAS batch call results in differnt report name than by hand?

Posted in reply to kjohnsonm

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));
Frequent Contributor
Posts: 129

Re: SAS batch call results in differnt report name than by hand?

When I run *this in the editor by hand I get nothing:
1374 %let path = %sysfunc(getoption(sysin));
1375 %put &path.;
SYMBOLGEN: Macro variable PATH resolves to

1376
1377
1378 %put The current program is %sysfunc(getoption(sysin));
The current program is


…with the program saved as c:\testing\temp.sas
When I run this in batch I get the name in the log as you suggest for the batch side but again as stated when run by hand I get a null string. Is there an option that I have set to something other than normal that might explain this? ??? I have no idea what might be causing this result…
Super User
Super User
Posts: 7,929

Re: SAS batch call results in differnt report name than by hand?

Posted in reply to kjohnsonm

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.

 

 

Super User
Super User
Posts: 7,929

Re: SAS batch call results in differnt report name than by hand?

Posted in reply to kjohnsonm

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.

 

Ask a Question
Discussion stats
  • 4 replies
  • 111 views
  • 1 like
  • 2 in conversation