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

Hello everyone, 

 

I am using a do loop to create a counter variable, count. However, the values that needs to be counted is not fully complete. How can I adjust the following code to include missing observations? I want to add a line that makes count=. if time=., and have no rows added if time=., but i couldn't get an if-then statement to work. Instead, the rows where time=. are removed from the dataset. 

 

Thank you!

 

 

data dat2; 
	set dat1; 
	if time ge 0 then do 
		count=1 to round(time, 1);
			output; 
			end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Try adding one more statement at the end of the DATA step:

 

else output;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Try adding one more statement at the end of the DATA step:

 

else output;

pamplemouse22
Calcite | Level 5

That worked! Thank you 🙂 

 

Haikuo
Onyx | Level 15
data dat2; 
	set dat1; 
if time=. then output;
	else if time ge 0 then do 
		count=1 to round(time, 1);
			output; 
			end;
run;
Tom
Super User Tom
Super User

You could just make sure your upper bound is at least 1.

data dat2; 
  set dat1; 
  do count=1 to max(1,round(time, 1));
    output; 
  end;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 766 views
  • 1 like
  • 4 in conversation