BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Mulvenon
Calcite | Level 5

Data problem where I need to append information to records ... my data are presented in the following fashion:

GHIN      Name   Date               Tees                 F9 B9 Tot  CR    CS

001362  Smith  06/10/2024  Green               36 38 74   68.1    119

            .                06/14/2024   Green               38 41 79         .         .

            .                06/22/2024   Green               41 40 81         .         .

001362  Smith  06/11/2024   Green_White  41  38  79   70.2  116

            .                 06/20/2024  Green_White  38 38  65         .      .

 

I need the data to be represented as:

 

GHIN      Name   Date               Tees                 F9 B9 Tot  CR    CS

001362  Smith  06/10/2024  Green               36 38 74   68.1    119

001362  Smith  06/14/2024   Green               38 41 79   68.1    119

001362  Smith  06/22/2024   Green               41 40 81   68.1    119

001362  Smith  06/11/2024   Green_White  41  38  79   70.2  116

001362  Smith  06/20/2024  Green_White  38 38  65   70.2  116

 

Does anyone know a quick way to complete this task? The dataset has approximately 2000 observations so need a programming solution. 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So when GHIN or NAME is missing, just use the last non-missing? Same for CR and CS?

 

data want;
    set have;
    retain ghin1 name1 cr1 cs1;
    if not missing(ghin) then ghin1=ghin;
    if not missing(name) then name1=name;
    if not missing(cr) then cr1=cr;
    if not missing(cs) then cs1=cs;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

So when GHIN or NAME is missing, just use the last non-missing? Same for CR and CS?

 

data want;
    set have;
    retain ghin1 name1 cr1 cs1;
    if not missing(ghin) then ghin1=ghin;
    if not missing(name) then name1=name;
    if not missing(cr) then cr1=cr;
    if not missing(cs) then cs1=cs;
run;
--
Paige Miller
Mulvenon
Calcite | Level 5

That worked exactly as I needed. 

 

Thanks Paige. 

data_null__
Jade | Level 19

The update trick saves you having to know the variables.  Typical LOCF.

 

data have;
   retain dummy 1;
   input  GHIN $ Name $  Date:mmddyy.  Tees :$16.  F9 B9 Tot CR CS;
   format date mmddyy10.;
   cards;
001362  Smith  06/10/2024  Green       36 38 74 68.1    119
.           .  06/14/2024  Green       38 41 79    .         .
.           .  06/22/2024  Green       41 40 81    .         .
001362  Smith  06/11/2024  Green_White 41 38 79 70.2  116
.           .  06/20/2024  Green_White 38 38 65   .      .  
;;;;
   run;
proc print;
   run;

data want;
   update have(keep=dummy obs=0) have;
   by dummy;
   output; *:-);
   run;

proc print;
   run;

Capture.PNG

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 1116 views
  • 2 likes
  • 3 in conversation