DATA Step, Macro, Functions and more

Problem with variable names when batching SAS

Reply
Occasional Contributor
Posts: 8

Problem with variable names when batching SAS

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

Trusted Advisor
Posts: 2,115

Re: Problem with variable names when batching SAS

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

Super User
Super User
Posts: 7,039

Re: Problem with variable names when batching SAS

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

Occasional Contributor
Posts: 8

Re: Problem with variable names when batching SAS

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

Regular Contributor
Posts: 227

Re: Problem with variable names when batching SAS

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

Respected Advisor
Posts: 3,799

Re: Problem with variable names when batching SAS

Posted in reply to Ron_Fehd_macro_maven

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

19         %let Yest = %sysfunc(intnx(DAY,%sysfunc(today()),-1),DDMMYYn.);
20         %put NOTE: &=yest;
NOTE: YEST=17042013
Ask a Question
Discussion stats
  • 5 replies
  • 374 views
  • 0 likes
  • 5 in conversation