BookmarkSubscribeRSS Feed
Thoney
Calcite | Level 5

Hi All,

I've been developing quite well on SAS over the past few months. I only come to you guys when I get so stumped even my manager doesn't know the answer (doesn't have time to work out the answer lol). I've got a section of SAS code that I need to run from a batch file everyday automatically. The issue with it is, it struggles with the variables I declare when run from the batch, but works absolutely fine if run from within SAS.

Example of the outputs;

This is the code and its output when run from within SAS:

data _Null_;

call symput('Yest',put(intnx('DAY',today(),-1),DDMMYYn.));

call symput('monyr',put(intnx('DAY',today(),-1),MONYY.));

run;

%put &Yest;

%put &monyr;

Output =

1     data _Null_;

2     /*today=today()-&i.;*/

3     call symput('Yest',put(intnx('DAY',today(),-1),DDMMYYn.));

4     call symput('monyr',put(intnx('DAY',today(),-1),MONYY.));

5     run;

NOTE: DATA statement used (Total process time):

      real time           0.04 seconds

      cpu time            0.00 seconds

6

7     %put &Yest;

06032013

8     %put &monyr;

MAR13

See how it has absolutely no trouble outputting 06032013 and MAR13??

When I run it from a batch file with the following code:

"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin "S:\Dept Reports 4\Collections Systems\Individual Folders\Thomas Honeyfield\Projects\Outbound Report\02 SAS Code\Inboundinfile.sas" -config "C:\Program Files\SAS\SAS 9.1\sasv9.cfg" -log "S:\Dept Reports 4\Collections Systems\Individual Folders\Thomas Honeyfield\Projects\Outbound Report\04 Process Logs\Inboundinfile.log"

I get a process log that looks like this:

9          data _Null_;
10         call symput('Yest',put(intnx('DAY',today(),-1),DDMMYYn.));
11         call symput('monyr',put(intnx('DAY',today(),-1),MONYY.));
12         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
     

WARNING: Apparent symbolic reference YEST not resolved.
13        
14         %put &Yest;
&Yest
15         %put &monyr;
WARNING: Apparent symbolic reference MONYR not resolved.
&monyr

This particular issue has driven me mad all day today, if anyone is having a go at answering and needs more surrounding code to get a better idea of what's gone wrong just say what you need and I'll elaborate.

Again many thanks in advance to anyone who takes a look, always have such a good response from you guys!

Tom

5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12

Tom,

It ran fine in batch for me (Win 7 Pro x64, SAS 9.3 TS1M1 32bit); I got the same thing you did for interactive SAS.

Rather than running that long script, try running it by right-clicking on the program icon and then submitting in batch.  That will tell you whether the problem is in your SAS install or something that you need to tweak in the script.

Also check the top of the batch log for warnings about missing configurations or something similar.

Doc Muhlbaier

Duke

Tom
Super User Tom
Super User

What statements were on lines 1 to 8 of the file you submitted batch mode?

Thoney
Calcite | Level 5

Hey I've come back to this old post to mark it as answered. I've had one hell of a busy month at work and only just got back around to this problem. Just wanted to make sure it's correctly marked as answered because Tom was right, when I looked at the initialisation it was showing that there was an issue resolving my user name and password. This in turn had a knock on effect where it ignored other variables in the code. Once I resolved my login and initialisation to SAS the batch ran perfectly fine as it did for Doc. Thanks again guys

p.s. can't see the option to mark as answered this time, is this because it's an old post? I hope I can still give people points for it

Tom

Ron_MacroMaven
Lapis Lazuli | Level 10

I am surprised this statement works.


call symput('Yest',put(intnx('DAY',today(),-1),DDMMYYn.));

note the format is

ddmmyyW.

Based on your original problem description

I believe there is/are some initializations that you have done in your session

that are not being done in batch.


As Tom requested:

"Show us the whole log"


This assignment can also be:

%let today= %sysfunc(today());

%let previous = %sysfunc(intnx(DAY,&today,-1));

%Let Yest = %sysfunc(putn(&previous,DDMMYYn.));

%put yest:&Yest;

%Let monyr = %sysfunc(putn(&previous,MONYY.));

%put monyr:&monyr;

Ron Fehd  dates maven

see also:

http://www.sascommunity.org/wiki/Macro_Loops_with_Dates

data_null__
Jade | Level 19

RTM %SYSFUNC has optional 2nd argument.:smileyinfo:

19         %let Yest = %sysfunc(intnx(DAY,%sysfunc(today()),-1),DDMMYYn.);
20         %put NOTE: &=yest;
NOTE: YEST=17042013

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
  • 1350 views
  • 0 likes
  • 5 in conversation