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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 8494 views
  • 0 likes
  • 2 in conversation