BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8

I was working on a data where a table has 3 columns in which some of the column values are missing for example: 

Kirito1_0-1673262910778.png

Now, I want to achieve something like this. Where LC_CODE is not provided we pick from LG_CODE and if LG_CODE is not provided we pick from referral code. And if we don't have any values for any of the columns we just leave it as blank.

So the desired output should be something like this as below

Kirito1_1-1673263063343.png

 

Something LIKE this 

Data FIN_EMP_CODE;
set MR7;
FIN_EMP_CODE = ;
if('LC Code'.MR7 NE . then 'LC Code'N = FIN_EMP_CODE);
else if ('LG Code'.MR7 NE . then 'LG Code'N = FIN_EMP_CODE);
else ('Referal Code'N.MR7 NE . then 'Referal Code'N = FIN_EMP_CODE);
run;

Can someone suggest what should I do to achieve this. Please, HELP!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Take a look at the COALESCE function.

View solution in original post

5 REPLIES 5
Kirito1
Quartz | Level 8
I am not even sure the pseudo code I wrote is correct or not.
Astounding
PROC Star
Take a look at the COALESCE function.
Kirito1
Quartz | Level 8
Can you suggest any quick pseudo code for this ...........Although I am reading the function you suggested.
PaigeMiller
Diamond | Level 26
data want;
    set have;
    ref_code=coalesce(lc_code,lg_code);
run;
--
Paige Miller
Kirito1
Quartz | Level 8
yep its working thank you

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 920 views
  • 2 likes
  • 3 in conversation