BookmarkSubscribeRSS Feed
renanm
Obsidian | Level 7

I've been looking for a way to fill null values with previous non-null values within the same group. 

 

While I know how to do that in SQL it took me a while to figure out in SAS. 

 

I have been able to figure out the code that will accomplish this. However, I'd like this to apply to only about 10 variables of about 100 variables I have in my data set. 

 

is there a way to apply the update to only selected variables with the below code? 

 

data Want;
   update MyData(obs=0) MyData;
   by ID;
   output;
run;
 
proc print data=Want;
run;

Thanks in advance !

3 REPLIES 3
Tom
Super User Tom
Super User

Just re-read those variables from the dataset.

Let's day you want to update only VAR1-VAR5 .

data Want;
   update MyData(obs=0) MyData ;
   by ID;
   set MyData (drop=Var1-Var5);
   output;
run;
renanm
Obsidian | Level 7

Hi @Tom , thanks for the reply. 

 

In your suggestion below, wouldn't the output data only contain VAR1-VAR5?

 

Ultimately I need the output dataset to contain all 100 variables VAR1-VAR100 but only retro-fill VAR1-VAR5. 

 

Thanks !

Tom
Super User Tom
Super User

@renanm wrote:

Hi @Tom , thanks for the reply. 

 

In your suggestion below, wouldn't the output data only contain VAR1-VAR5?

 

Ultimately I need the output dataset to contain all 100 variables VAR1-VAR100 but only retro-fill VAR1-VAR5. 

 

Thanks !


No. Try it.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 474 views
  • 5 likes
  • 2 in conversation