Quantcast
Viewing all articles
Browse latest Browse all 310

using the "-" symbol to refer to many datasets

Hello all,

hopefully someone can help understand why something is not working.

To summarize some background, I used macros and do-loops to create many datasets, for instance:

data2009_1_1
data2009_1_2
data2009_1_3
data2009_2_1
data2009_2_2
....
....
and so on.

As you can see there are 3 groups of numbers which are separated by underscores. What I want to do now is to merge datasets that have the same first 2 numbers. So, I want to merge data2009_1_1 data2009_1_2 data2009_1_3 with one another.

I know I could accomplish this with:

data merge;
merge data2009_1_1 - data2009_1_3;
run;

Hence, I could use the "-" symbol to merge a bunch of similarly named datasets whose number at the end increases by 1.

HOWEVER......sometimes I want to merge 4 datsets, sometimes I want to merge 2, sometimes I want to merge 5....it varies. So, what I did was to create a macro variable that found the maximum number of datasets that I want to merge. Essentially, my code to merge the datasets is as follows:

%macro pareto_merge(var=);
proc sql noprint;
select max(&var) into: maxvar
from obesity;
run;

%do k=2009 %to 2010;
%do j=1 %to 1;
data histomerge&k._&j;
merge &var&k._&j._1 - &var&k._&j._&maxvar;
run; quit;
%end;
%end;
%mend;

Where the &maxvar represents the highest number. However, it never seems to work and I get an error in the log saying it expects a numeric value where &maxvar is.

I know tha &maxvar = some number (for instance 4). If I replace &maxvar with 4, this code works - but I don't really want to have to specify a number since I want this process as automated as possible. Any suggestions (assuming anyone could actually follow my rambling) on why this wouldn't work?

Viewing all articles
Browse latest Browse all 310

Trending Articles