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;
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.
What do you want to do? What do you want &&m&i. to resolve to?
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.
I will ask tomorrow, look like nobody can help me today with it. 😞
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.