BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

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;

dupes.PNG

 

I only need to keep one "ord3=0"

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
mklangley
Lapis Lazuli | Level 10

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;
novinosrin
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1915 views
  • 0 likes
  • 3 in conversation