07-15-2011 11:38 AM
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.
07-15-2011 12:13 PM
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.
07-15-2011 01:22 PM
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.
%do j=1 %to &end1;
%do k=1 %to &end2;
proc corr data=corrprep outs=out noprint;
var I&j I&j.S&k;
set out (rename=(i&j=corr));
keep _Name_ corr;
proc append base=out1 data=out;run;
07-15-2011 02:00 PM
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.
07-15-2011 02:03 PM
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.
07-15-2011 02:21 PM
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
07-15-2011 05:10 PM
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;
07-22-2011 04:34 PM
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.
07-25-2011 12:11 PM
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)
%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 in each environment ;
proc compare base= cmplib.batch compare= cmplib.interactive
outall outnoequal out= cmplib.optn_diffs ;
id optname ;
or something like that