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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 382 views
  • 2 likes
  • 3 in conversation