BookmarkSubscribeRSS Feed
Primohunter
Obsidian | Level 7

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

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 791 views
  • 0 likes
  • 3 in conversation