BookmarkSubscribeRSS Feed
aidant01
Fluorite | Level 6

 

Hi everyone, 

 

I'm trying to fill in empty cells using the value from the first non-missing cell to the left of that empty cell in each row. The table runs from January 1, 2014 through August 1, 2018. For example:

 

Screen Shot 2018-09-25 at 6.49.06 PM.png

 

 

I tried:

 

data desiredtable;

set rawtable;

if variable=. then lag(variable);

end;

run;

 

But seems like this only works if the table was set up in long format vs. wide format. 

 

Any help is appreciated. Thanks. 

 

-Aidan

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
  input A B C D E F G H  ;
  cards;
. 1 . 2 3 . . .
run;
data WANT;
  set HAVE;
  array ARR [8] A -- H ;
  do I=2 to 8;
    if ARR[I]=. then ARR[I]=ARR[I-1];
  end;
run;

 

aidant01
Fluorite | Level 6

Thanks Chris it worked!

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 25. 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
  • 2 replies
  • 1429 views
  • 0 likes
  • 2 in conversation