Hi,
I am using do loops to create table shells but it is create extra rows I do not need.
data shell;
do ord1= 1 to 5; /*params*/
do ord2= 2 ,5 ,6 ,7 ,8 ,9 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19; /*avisitn*/
do ord3= 0 to 6; /*summary statistics*/
output;
end;
end;
end;
run;
I only need to keep one "ord3=0"
HI @HitmonTran Please try if you like
data shell;
do ord1= 1 to 5;
_n_=0;
do ord2= 2 ,5 ,6 ,7 ,8 ,9 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19;
_n_+1;
do ord3= 0 to 6;
if _n_>1 and ord3=0 then
continue;
/*summary statistics*/
output;
end;
end;
end;
run;
Could you clarify--do you want ord3 = 0 only once in all, or only once for each loop of ord1?
Here are solutions for each (respectively):
data shell;
do ord1= 1 to 5;
do ord2= 2 ,5 ,6 ,7 ,8 ,9 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19;
if(ord1 = 1 and ord2 = 2) then do;
do ord3= 0 to 6;
output;
end;
end;
else do;
do ord3= 1 to 6;
output;
end;
end;
end;
end;
run;
data shell;
do ord1= 1 to 5;
do ord2= 2 ,5 ,6 ,7 ,8 ,9 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19;
if(ord2 = 2) then do;
do ord3= 0 to 6;
output;
end;
end;
else do;
do ord3= 1 to 6;
output;
end;
end;
end;
end;
run;
HI @HitmonTran Please try if you like
data shell;
do ord1= 1 to 5;
_n_=0;
do ord2= 2 ,5 ,6 ,7 ,8 ,9 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19;
_n_+1;
do ord3= 0 to 6;
if _n_>1 and ord3=0 then
continue;
/*summary statistics*/
output;
end;
end;
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.