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

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_IDDate1Date2Date3Date4Date_New
121031-Mar-09...31-Mar-09
1210.30-Jun-09..30-Jun-09
1210..30-Sep-09.30-Sep-09
1210.....
1210...31-Mar-0931-Mar-09


Thank you in advance for your kind support!


1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

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

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

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

mmh
Obsidian | Level 7 mmh
Obsidian | Level 7
Thanks a lot for your kind response!
Tom
Super User Tom
Super User

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;
mmh
Obsidian | Level 7 mmh
Obsidian | Level 7
Hello Tom,
Thank you so much for your reply!
In my dataset, there is no instance where there might be more than one non-missing value.
Thanks for asking 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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