Hi All,
I need to duplicate an observation while a condition is not true. I want to duplicate esiid1 when the value in recorder does not equal 1. Here's my latest attempt.
data esiid3;
set recorder;
Do while (recorder ne 1);
output esiid1;
end;
run;
May be you can try this after weekend. Have a great long weekend!
data have;
set recorder;
if recorder=1 then grp+1;
run;
data esiid3 (drop=esiid1 grp rename=esiid2=esiid1);
set have;
by grp;
retain esiid2;
if first.grp then esiid2=esiid1;
run;
proc print data=esiid3;
run;
Without any data, either what you have or need we're throwing darts in the dark:
data esiid3;
set recorder;
if recorder ne 1 then output;
output;
run;
I need the value in esiid1 to duplicate until it encounters the next esiid1 where the recorder = 1.
Something like this may generate desired output.
data esiid3;
set recorder;
retain esiid1;
if recorder = 1 then esiid1=ESIID;
run;
Hi, no that just output a data set that matches the input set recorder. I think retain is on the right path though!
recorder is a character variable (leading zeros), newrecorder is numeric so you're code would have to change according but I think @stat@Sas code would work otherwise.
data esiid3;
set recorder;
retain esiid1;
if newrecorder = 1 then esiid1=ESIID;
run;
Doh! Sorry my bad on the newrecorder! I still can't get the desired dataset though. I'll play with it more Monday. I'm out for a 4 day weekend! Thanks for all the help folks!
Steve
May be you can try this after weekend. Have a great long weekend!
data have;
set recorder;
if recorder=1 then grp+1;
run;
data esiid3 (drop=esiid1 grp rename=esiid2=esiid1);
set have;
by grp;
retain esiid2;
if first.grp then esiid2=esiid1;
run;
proc print data=esiid3;
run;
Well that did the trick! Thanks so much! Have a good weekend!
Steve
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.