You are right. I have updated my code. Thanks - Linlin
Linlin,
your code is short, efficient, and easy and It worked.
Thanks.
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
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.
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!
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.