No, just ignore that option. Not needed. Will work without it
/*Added additional variables to the sample HAVE*/
data have;
input id day drinks ;
blah=rand('integer',1,100);
blahblah=rand('integer',1,100);
blahblahblah=rand('integer',1,100);
cards;
1 2 1
1 3 3
1 5 4
2 3 1
3 2 1
3 4 2
;
data want;
if _n_=1 then do;
if 0 then set have;
dcl hash H (dataset:'have') ;
h.definekey ("id",'day') ;
h.definedata ("drinks") ;
h.definedone () ;
end;
set have(keep=id blah blahblah blahblahblah);
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then drinks=0;
output;
end;
drop rc;
run;
A BIG THANKS TO YOU!!!
You are welcome! have a good one!
Thanks @novinosrin for providing data in usable form.
Another way to solve the issue:
data want;
set have;
by id;
length expectedDay backupDay backupDrinks 8;
retain expectedDay;
drop expectedDay backupDay backupDrinks;
if first.id then do;
expectedDay = 1;
end;
if day ^= expectedDay then do;
backupDay = day;
backupDrinks = drinks;
drinks = 0;
do day = expectedDay to backupDay-1;
output;
end;
drinks = backupDrinks;
end;
output;
expectedDay = day + 1;
if last.id and day ^= 5 then do;
drinks = 0;
do day = day+1 to 5;
output;
end;
end;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.