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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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