BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kyle
Calcite | Level 5

I have been trying to get this input:

ID     VAR_1       VAR_2      VAR_3

001      1                              3    

001                    2

002                    2

002    1

002                     2               3

To this output:

ID     VAR_1       VAR_2     VAR_3

001     1               2               3

002     1               2               3

Here is my test dataset. I used RETAIN to get them all line up at the end, then take the LAST.ID. However the retain does not seem to work...

data a;

input id $ 1-3 var_1 $ 4-4 var_2 $ 5-5 var_3 $ 6-6;

cards;

0011 3

001 2

002 23

0021

002 3

;

Any ideas. Thanks!

-K

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the UPDATE statement.  Only non-missing values will cause changes to previous value.

data have ;

input ID VAR_1 VAR_2 VAR_3 ;

cards;

001 1 . 3

001 . 2 .

002 . 2 .

002 1 . .

002 . 2 3

run;

data want ;

  update have (obs=0) have;

  by id;

run;

data _null_;

  set want ;

  put (_all_) (=);

run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Use the UPDATE statement.  Only non-missing values will cause changes to previous value.

data have ;

input ID VAR_1 VAR_2 VAR_3 ;

cards;

001 1 . 3

001 . 2 .

002 . 2 .

002 1 . .

002 . 2 3

run;

data want ;

  update have (obs=0) have;

  by id;

run;

data _null_;

  set want ;

  put (_all_) (=);

run;

Kyle
Calcite | Level 5

Thanks Tom, that was quickSmiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 2588 views
  • 0 likes
  • 2 in conversation