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

That's over-optimistic I reckon. An updated message and documentation is all we'll get.

Astounding
PROC Star

Here's a version that works when you have many variables, not just 2 or 3:

 

proc sort data=have;

by case_id state;

run;

 

data want;

update have (obs=0) have;

by case_id;

run;

 

It also works when you have many observations per CASE_ID.

PGStats
Opal | Level 21

@Astounding, you may end up with unwanted results with UPDATE

 

data have;
input case_id state1 $ state2 $;
datalines;
1 A .
1 . .
1 . B
;

proc sort data=have;
by case_id state1 state2;
run;

data want;
update have (obs=0) have;
by case_id;
run;

proc print; run;
                         Obs    case_id    state1    state2

                          1        1         A         B
PG
Astounding
PROC Star

@PGStats, you're right about the possibility of complications.  But it's difficult to tell what is really necessary here.  The original post is likely to be a simplification of the actual scenario so I wanted to make sure the UPDATE program was at least considered.  The example that you posted might actually be a desirable result ... it's up to the original poster to decide.

 

Note that I had the data set sorted by STATE so that non-missing-values the non-missing STATE observation would prevail if there is a conflict.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 18 replies
  • 3619 views
  • 7 likes
  • 7 in conversation