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

I am trying to make a DO Loop that does two things:

1) Create a variable called Mouse ID that repeats the values 1-15, which each value being repeated 8 times.

2) Create a variable called Day, so basically DO Day = 0 TO 28 BY 4. The issue is also getting this repeated for all the 15 mice.

 

The output should start like this, and at the end produce output with 120 variables.

 

Mouse ID       Day

1                     0

1                     4

1                     8

1                     12

1                     16

1                     20

1                     24

1                     28

2                     0

2                     4

.....

How do I make this DO Loop for this?

 

This is what I started with, but need ideas for how to get everything repeated an appropriate number of times

data WORK.Illus;
do MouseID = 1 to 15;
do Day = 0 to 28 by 4;
output;
end;
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

15 Mouse * 8 repititions is 120, but your code already does that....

 

 

You can add the 1 to 120 by adding in a counter if you want.

 

data WORK.Illus;
	N=0;

	do MouseID = 1 to 15;
			do Day = 0 to 28 by 4;
				N+1;
				output;
			end;
	end;
run;

View solution in original post

5 REPLIES 5
Reeza
Super User

That looks right, I think you need another DO loop for the 8 records though, but I'm not sure what you want as a final structure so that will tell you were to put the 8 loop. I think it likely goes in between your current loops.

 

data WORK.Illus;
	do MouseID = 1 to 15;
		do Rep = 1 to 8;
			do Day = 0 to 28 by 4;
				output;
			end;
		end;
	end;
run;
marianhabesland
Calcite | Level 5

Thanks for your answer! So that repeats the Day how I was thinking. The issue is that it repeats the Mouse ID from 1-8, each eight times and then starts repeating from 1 again. I need the variable 1-15 to each repeat eight times. Do I need another repeat statement somewhere?

marianhabesland
Calcite | Level 5

 

MouseID

Day

1

1

0

2

1

4

3

1

8

4

1

12

118

15

20

119

15

24

120

15

28

 

This table shows the end of the output as well as it is supposed to look

Reeza
Super User

15 Mouse * 8 repititions is 120, but your code already does that....

 

 

You can add the 1 to 120 by adding in a counter if you want.

 

data WORK.Illus;
	N=0;

	do MouseID = 1 to 15;
			do Day = 0 to 28 by 4;
				N+1;
				output;
			end;
	end;
run;
marianhabesland
Calcite | Level 5

Ok, yeah that works. I think the issue was the repeat statement. It kept repeating from 1 to 8 rather than 1 to 15, so when I removed that it worked. Thanks!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 8387 views
  • 0 likes
  • 2 in conversation