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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: