BookmarkSubscribeRSS Feed
lsirakos
Calcite | Level 5

I am having a bit of trouble figuring out why this is happening but I have some code I am running in SAS and when I do, everything runs fine but when I run it in batch I receive errors that do not make sense (things like certain variables not being found and whatnot).  I am using macros and macro variables so I don't know if that has something to do with it and I don't think it should but it is about all I can figure.  I can start a brand new SAS session, import data files, and run the code and it runs fine but when I try to do the same thing in batch it doesn't work. 

Anyone else have an issue like this and without posting the code due to confidentiality reasons any suggestions for debugging?  All the code is doing is a lot of datastep manipulation, proc means a couple times outputting averages, and a macro that runs a lot of different proc corrs.

8 REPLIES 8
DF
Fluorite | Level 6 DF
Fluorite | Level 6

It sounds like there must be something different between your batch and interaction modes when running.

I would guess you might have an autoexec (etc.) that's setting variables you required, that then fail because batch mode isn't running the required setup code.

What might help is to trace back from the first error (e.g. an undefined macro variable), and work out where that should've been getting its value from.  That might give you a better clue as to the issue.

If you could construct a simple example that reproduces your issue, but without listing confidential data, that might help too.

lsirakos
Calcite | Level 5

Here is basically what my macro is where things seem to fall apart as there aren't any errors until I reach this stage.  There might (and probably is) a better way to do this but what I am doing is I have a dataset with a lot of variables that I need to run proc corr on and I used the naming convention of I# for one type of variable and I#S# for the other variable to find the correlation between.  For example, one variable will be I1 and I will find the correlation between that and I1S1, I1S2, I1S3, etc and then it goes to I2 and does the same thing.  I then take the correlations and output it to a dataset and then append it to a growing dataset to contain all the correlations.  Like I said, it runs fine in SAS, just not in batch.

%macro Test;

%do j=1 %to &end1;

data getMacro;
set otherdataset;
where Num1=&j;
call symputx('end2',countNum);
run;

%do k=1 %to &end2;

proc corr data=corrprep outs=out noprint;
var I&j I&j.S&k;
run;

data out;
set out (rename=(i&j=corr));
if _N_=5;
keep _Name_ corr;
run;

proc append base=out1 data=out;run;

%end;

%end;
%mend Test;

Tom
Super User Tom
Super User

The macro is referencing a macro variable END1 that is not defined in the code you posted. Perhaps in your interactive session you defined that macro variable and so the code runs.

You are not testing whether you find any values of NUM1=&J when you are trying to define the macro variable END2. Print out the dataset OTHERDATASET and make sure that the values of NUM1 and COUNTNUM are valid for your data.

Why not just run PROC CORR on all the variables and the post process the output dataset with a data step and avoid the macro variables?  Not sure what macro code is adding here.

lsirakos
Calcite | Level 5

I did define that variable elsewhere and the reason I am using a macro is so this is a repeatable process no matter how many different variables there are.  I need it to handle however much (or little) data is being analyzed without changing the code.

art297
Opal | Level 21

It was mentioned before, but I didn't notice a response from you.  Do you have an autoexec.sas file?  If not, take a look at: http://www.wuss.org/proceedings10/coders/2937_4_0_COD_Walsh.pdf

Tom
Super User Tom
Super User

Can you post any error message?  Or are you just not getting the expected output.

Have you tried the WITH statement in PROC CORR?  You should be able to eliminate the %DO K loop from your macro. And hence also the need pull END2 from a dataset.

Prehaps something like this?

%macro test(end);
  %do J=1 %to &end ;
    proc corr data=corrprep outs=out noprint;
      var I&J ;
      with I&J.S: ;
    run;
    proc append base=out1
      data=out (where=((upcase(_name_)="I&J") rename=(I&j = corr) ) 
    ;
    run;
  %end;
%mend;

%test(&end1)

lsirakos
Calcite | Level 5

Sorry for my delayed response, I was unable to log in for whatever reason.  Thank you Tom, I was not aware of the with statement and it made the program work much better to the point where I don't need to worry about using batch mode after all.

Thanks again.

Peter_C
Rhodochrosite | Level 12

Isirakos

if you should bump into that problem (different behaviour in batch and interactive SAS)  then one investigation you should perform is comparison of system options. Normally there are differences between batch and interactive SAS. Some of the settings might not be as helpful as intended. Two ways

1 in batch and interactive SAS, run proc options and collect log and store for comparison later. Then perform text compare of the stored logs (if nothng else available, ms-word can do a text compare)

2

%let version = batch or interactive depending ; *(not sure if there is a reliable &SYSmacroVariable  for this);

libname cmplib 'somewhere safe' ;

data cmplib.&version ;

set  sashelp.voption ;

run ;

* run in each environment ;

proc compare base= cmplib.batch compare= cmplib.interactive

           outall outnoequal out= cmplib.optn_diffs ;

id optname ;

run ;

or something like that

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 4099 views
  • 0 likes
  • 5 in conversation