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;
Try adding one more statement at the end of the DATA step:
else output;
Try adding one more statement at the end of the DATA step:
else output;
That worked! Thank you 🙂
data dat2;
set dat1;
if time=. then output;
else if time ge 0 then do
count=1 to round(time, 1);
output;
end;
run;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.