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

Hi everyone.

 

I want to get the missing information in var1 from var2. 

Sometimes var1 already has the information (e.g. inputs 1 and 4). But sometimes information for both var1 and var2 are not missing. Can be similar (e.g. input3) and dissimilar (e.g. input5). In case of dissimilar information, the information in var1 is always selected.

 

The data looks like this.

 

data ddd;

input ID var1 $ var2 $;

cards;

1 a .  

2 . b

3 c c

4 d .

5 e f 

;

run;

 

I would like a new column (new_var) to be added to the file to look like this.

 

input   new_var

1             a

2             b

3             c

4             d

5             e

 

Thanks for your help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

If var1 and var2 are character, use function coalescec:

 

new_var = coalescec (var1, var2) ;

PG

View solution in original post

2 REPLIES 2
Astounding
PROC Star
new_var = coalesce (var1, var2) ;
PGStats
Opal | Level 21

If var1 and var2 are character, use function coalescec:

 

new_var = coalescec (var1, var2) ;

PG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 590 views
  • 2 likes
  • 3 in conversation