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

Hi,

I have a dataset like this:

ID     Proc1              Proc2         Proc3                 Proc4

10                                              03/30/2021 

10     03/31/2021

10                                                                        03/27/2021

20    03/20/2021

20                         03/20/2021    

20                                              03/20/2021 

20                                                                        03/20/2021

I want to have a table like this as the output

ID   Proc1           Proc2            Proc3               Proc4

10  03/31/2021    NA               03/30/2021      03/27/2021

20  03/20/2021   03/20/2021   03/20/2021     03/20/2021

Is there any way that I can get such an output?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
  infile datalines dsd missover;
  input ID (Proc1 Proc2 Proc3 Proc4)(:mmddyy10.);
  format Proc1-Proc4 mmddyy10.;
datalines;
10,,,03/30/2021 
10,03/31/2021
10,,,,03/27/2021
20,03/20/2021
20,,03/20/2021
20,,,03/20/2021 
20,,,,03/20/2021
;
run;

proc format;
   value DateNA
      . = 'N/A'
      other = [mmddyy10.]
   ;
run;

data want;
 update have(obs=0) have;
 by id;
 format proc: datena.;
 run;

View solution in original post

6 REPLIES 6
ballardw
Super User

Are the variables Proc1 through Proc4 numeric (with a date format applied) or character?

 

Such details matter.

Bright
Obsidian | Level 7

Yes they are numeric with date format.

Bright
Obsidian | Level 7
Yes they are numeric with the date format.
japelin
Rhodochrosite | Level 12

how about this.

data have;
  infile datalines dsd missover;
  input ID (Proc1 Proc2 Proc3 Proc4)(:mmddyy10.);
  format Proc1-Proc4 mmddyy10.;
datalines;
10,,,03/30/2021 
10,03/31/2021
10,,,,03/27/2021
20,03/20/2021
20,,03/20/2021
20,,,03/20/2021 
20,,,,03/20/2021
;
run;

data want;
  set have;
  by id;
  array prockeep{4} _temporary_;
  array procvar{4} proc1-proc4;
  retain prockeep:;
  if first.id then do;
    do i=1 to dim(prockeep);
      prockeep{i}=.;
    end;
  end;
  do i=1 to dim(prockeep);
    if procvar{i}^=. then prockeep{i}=procvar{i};
  end;
  if last.id then do;
    do i=1 to dim(prockeep);
      procvar{i}=prockeep{i};
    end;
    output;
  end;
  drop i;
run;

Variables are numeric, so it can't be display NA.

 

andreas_lds
Jade | Level 19

By using a custom format, missing values can displayed as  "n/a". I would not attach such format to a dataset, but use it in printing procs.

proc format;
   value DateNA
      . = 'N/A'
      other = [mmddyy10.]
   ;
run;

proc print data=want;
   format proc: DateNA.;
run;
Ksharp
Super User
data have;
  infile datalines dsd missover;
  input ID (Proc1 Proc2 Proc3 Proc4)(:mmddyy10.);
  format Proc1-Proc4 mmddyy10.;
datalines;
10,,,03/30/2021 
10,03/31/2021
10,,,,03/27/2021
20,03/20/2021
20,,03/20/2021
20,,,03/20/2021 
20,,,,03/20/2021
;
run;

proc format;
   value DateNA
      . = 'N/A'
      other = [mmddyy10.]
   ;
run;

data want;
 update have(obs=0) have;
 by id;
 format proc: datena.;
 run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1315 views
  • 2 likes
  • 5 in conversation