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.

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
  • 981 views
  • 5 likes
  • 2 in conversation