BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Linlin
Lapis Lazuli | Level 10

You are right. I have updated my code.  Thanks - Linlin

sasuser3
Calcite | Level 5

Linlin,

your code is short, efficient, and easy and It worked.

Thanks.

antony_allianz
Fluorite | Level 6

proc means data=y n;

var id;

run;

proc sort data=y out=y1;

by gender;

run;

data male female;

set y1;

if gender='m' then output male;

else if gender='f' then output female;

run;

data x;

set male;

retain Mno;

if first.gender='m' then Mno+1;

if last.gender;

run;

data x1;

set female;

retain Fno;

if first.gender='f' then Fno+1;

if last.gender;

run;

data gp1 gp2 gp3;

set x;

Mcnt=Mno/31;

g1=Mcnt*10;

g2=Mcnt*11;

do i=1 to Mno;

if i<= g1 then output gp1;

g4=g1+g1;

else if  g1 <i<= g4 then output gp2;

g6=g4+g2;

else if  g4<i<= g6 then output gp3;

end;

run;

data gp4 gp5 gp6;

set x1;

Fcnt=Fno/31;

gf1=Fcnt1*10;

gf2=fcnt*11;

do i=1 to Fno;

if i<= gf1 then output gp4;

gf4=gf1+gf1;

else if  gf1 <i<= gf4 then output gp5;

gf6=gf4+gf2;

else if  gf4<i<= gf6 then output gp6;

end;

run;

then Append the datasets gp1 & gp4,gp2 & gp5 and gp3 & gp6

PaigeMiller
Diamond | Level 26

antony@allianz wrote:

proc means data=y n;

var id;

run;

proc sort data=y out=y1;

by gender;

run;

data male female;

set y1;

if gender='m' then output male;

else if gender='f' then output female;

run;

data x;

set male;

retain Mno;

if first.gender='m' then Mno+1;

if last.gender;

run;

data x1;

set female;

retain Fno;

if first.gender='f' then Fno+1;

if last.gender;

run;

data gp1 gp2 gp3;

set x;

Mcnt=Mno/31;

g1=Mcnt*10;

g2=Mcnt*11;

do i=1 to Mno;

if i<= g1 then output gp1;

g4=g1+g1;

else if  g1 <i<= g4 then output gp2;

g6=g4+g2;

else if  g4<i<= g6 then output gp3;

end;

run;

data gp4 gp5 gp6;

set x1;

Fcnt=Fno/31;

gf1=Fcnt1*10;

gf2=fcnt*11;

do i=1 to Fno;

if i<= gf1 then output gp4;

gf4=gf1+gf1;

else if  gf1 <i<= gf4 then output gp5;

gf6=gf4+gf2;

else if  gf4<i<= gf6 then output gp6;

end;

run;

then Append the datasets gp1 & gp4,gp2 & gp5 and gp3 & gp6

Obviously, there are many ways to solve this problem. I have a strong desire for the simplest solution whenever I write code, so this would fail on that score. The code posted by LinLin seems to be about as simple as it can get; and so I don't see any reason to use this code.

--
Paige Miller

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 11622 views
  • 5 likes
  • 7 in conversation