Hello,
I am a new SAS user.
I want to create a new column showing the non-missing value.
However, when all the column values are missing, the output column will show a missing value too.
I have the following dataset:
data have;
input Company_ID $4. Date1 Date2 Date3 Date4;
informat Date1 Date2 Date3 Date4 date9.;
format Date1 Date2 Date3 Date4 date9.;
cards;
1210 31mar2009 . . .
1210 . 30jun2009 . .
1210 . . 30sep2009 .
1210 . . . .
1210 . . . 31mar2009
;
run;
I am expecting the following output:
| Company_ID | Date1 | Date2 | Date3 | Date4 | Date_New |
| 1210 | 31-Mar-09 | . | . | . | 31-Mar-09 |
| 1210 | . | 30-Jun-09 | . | . | 30-Jun-09 |
| 1210 | . | . | 30-Sep-09 | . | 30-Sep-09 |
| 1210 | . | . | . | . | . |
| 1210 | . | . | . | 31-Mar-09 | 31-Mar-09 |
Thank you in advance for your kind support!
Hello,
data have;
input Company_ID $4. Date1 Date2 Date3 Date4;
informat Date1 Date2 Date3 Date4 date9.;
format Date1 Date2 Date3 Date4 date9.;
cards;
1210 31mar2009 . . .
1210 . 30jun2009 . .
1210 . . 30sep2009 .
1210 . . . .
1210 . . . 31mar2009
;
run;
data want;
set have;
Date_New = max(of date1-date4);
format Date_New date9.;
run;
/* end of program */
Koen
Hello,
data have;
input Company_ID $4. Date1 Date2 Date3 Date4;
informat Date1 Date2 Date3 Date4 date9.;
format Date1 Date2 Date3 Date4 date9.;
cards;
1210 31mar2009 . . .
1210 . 30jun2009 . .
1210 . . 30sep2009 .
1210 . . . .
1210 . . . 31mar2009
;
run;
data want;
set have;
Date_New = max(of date1-date4);
format Date_New date9.;
run;
/* end of program */
Koen
What value you want when there is more than one non-missing value?
data want;
set have;
date_new=min(of date1-date4);
format date_new date9.;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.