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

Hello,

 

I have the following data structure and am wondering how to get the second data structure from SAS.

 

What I have:

Case  Payment1 Payment2

1         $100          .

2          .                 $200 

3           $300           .

 

What I want:

Case  PaymentNew 

1         $100          

2          $200 

3           $300           

 

In this particular case, payment 1 and 2 are mutually exclusive so only one (not both) is paid per case.

 

Thanks

Laura

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input Case Payment1 Payment2;
datalines;
1 100 .
2 . 200 
3 300 .
;

data want;
	set have;
	Payment=coalesce(of Payment:);
    keep Case Payment;
run;

 

Result:

 

Case  Payment 
1     100
2     200
3     300

 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @lmyers2  Use coalesce function

PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input Case Payment1 Payment2;
datalines;
1 100 .
2 . 200 
3 300 .
;

data want;
	set have;
	Payment=coalesce(of Payment:);
    keep Case Payment;
run;

 

Result:

 

Case  Payment 
1     100
2     200
3     300

 

SuryaKiran
Meteorite | Level 14

Hello,

 

Will you be having only one payment and the rest are missing? Then as others suggested coalesce will work fine, but if you have multiple payments and would like to sum them then use sum() function which ignores missing values.

 

data want;
	set have;
	Payment=sum(of Payment:);
    keep Case Payment;
run;
Thanks,
Suryakiran

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 430 views
  • 0 likes
  • 4 in conversation