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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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