Hello everyone, i have a question regarding the creation of a column based on another, as you can read in the subject.
Example
HAVE DATASET:
V0 V1
1 23/11/22
2 24/11/22
3 .
4 21/11/22
WANT DATASET:
V0 V1 V2
1 23/11/22 23/11/22
2 24/11/22 24/11/22
3 . 24/11/22
4 21/11/22 21/11/22
Thank you all, in advance
Try this
data have;
input V0 V1 :ddmmyy8.;
format V1 ddmmyy8.;
datalines;
1 23/11/22
2 24/11/22
3 .
4 21/11/22
;
data want;
set have;
if V1 then _iorc_ = V1;
V2 = _iorc_;
format V2 ddmmyy8.;
run;
Result:
V0 V1 V2 1 23/11/22 23/11/22 2 24/11/22 24/11/22 3 . 24/11/22 4 21/11/22 21/11/22
This doesn't seem to find the max value of V1 and use that in V2 when V1 is missing.
How about this:
proc summary data=have;
var v1;
output out=max max=v1_max;
run;
data want;
if _n_=1 then set max;
set have;
v2=coalesce(v1,v1_max);
drop _type_ _freq_ v1_max;
format v2 ddmmyy8.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.