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
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
Hi @lmyers2 Use coalesce function
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
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;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.