BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Luis3
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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

Luis3
Fluorite | Level 6

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.

Luis3
Fluorite | Level 6

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

Astounding
PROC Star

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.

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
  • 4 replies
  • 610 views
  • 0 likes
  • 3 in conversation