Double Macrovariable

Solved
Occasional Contributor
Posts: 8

Double Macrovariable

Hi everyone,

I hope you can help me with this.

data have;

input subjid count;

datalines;

1 145

2 124

3 34

4 65

5 180

;

data want0 ;

set have end=last;;

by subjid;

if last then call symput('totsub',put(subjid,best.));

run;

%put &totsub.;

data _null_;

SET WANT0;

call symputx(cats('M',subjid),count);

run;

%put &m5.;

data want;

set want0;

do i=1 to &totsub.;

do j=1 to &&m&i.; ***it doesnt work, I need help on this;

output;

end;

end;

run;

Accepted Solutions
Solution
‎09-10-2017 10:19 AM
Super User
Posts: 6,928

Re: Double Macrovariable

Is there a reason you need to use macro language here?  You certainly could use your existing data set with no macro language to accomplish this objective:

data want;

set have;

do j=1 to count;

output;

end;

run;

If that doesn't do the job, we might need to know what "doesn't work" means.  Clearly, you would be asking for the wrong number of observations:

do j=1 to &&m&i .;

The value of &i is determined before the DATA step begins to execute.  It does not change on each observation.  It is constant across all observations, and is unrelated to the DATA step variable named i.

All Replies
PROC Star
Posts: 1,400

Re: Double Macrovariable

What do you want to do? What do you want &&m&i. to resolve to?

Occasional Contributor
Posts: 8

Re: Double Macrovariable

Hi, I want different loops,

1 to m1

1 to m2

1 to m3

1 to m4

1 to m5

I thought &&m&i could do the job.

Basically, i want a dataset that goes from subjid=1 with m1 records, subjid=2 with m2 records,....and subjid=5 with m5 records.

thanks.

Occasional Contributor
Posts: 8

Re: Double Macrovariable

I will ask tomorrow, look like nobody can help me today with it.

Solution
‎09-10-2017 10:19 AM
Super User
Posts: 6,928

Re: Double Macrovariable

Is there a reason you need to use macro language here?  You certainly could use your existing data set with no macro language to accomplish this objective:

data want;

set have;

do j=1 to count;

output;

end;

run;

If that doesn't do the job, we might need to know what "doesn't work" means.  Clearly, you would be asking for the wrong number of observations:

do j=1 to &&m&i .;

The value of &i is determined before the DATA step begins to execute.  It does not change on each observation.  It is constant across all observations, and is unrelated to the DATA step variable named i.

☑ This topic is solved.