BookmarkSubscribeRSS Feed
subhani4
Obsidian | Level 7

i have the below code, which generate column O as 1 for 300 observations. But i want to get an output in such a form like o=1 for (1 to 6) obs and o=2 for (7 to 12) obs  and so on o=50 for obs (295 to 300).

 

Could any one help me regarding the same. Thanks in advance!!.

 

data temp;
do i=1 to 300 by 6;
do j=i to i+5;
o=1;
output;
end;
end;
run;

3 REPLIES 3
Patrick
Opal | Level 21

Below should work independent on how you define your loop(s).

data temp(drop=_:);
  do i=1 to 300 by 6;
    do j=i to i+5;
      _o+1;
      o=ceil(_o/6);
      output;
    end;
  end;
  stop;
run;

 

Astounding
PROC Star
Try:

data temp;
do i = 1 to 300 by 6;
o + 1;
do j = i to i+5;
output;
end;
end;
run;
FreelanceReinh
Jade | Level 19

If O is the only variable you need in dataset TEMP, this is sufficient:

data temp;
do _n_=1 to 300;
  o+(mod(_n_,6)=1);
  output;
end;
run;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 667 views
  • 0 likes
  • 4 in conversation