BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

dear all

I have to impute the missing values with the immediately preceeding value in the series.

earlier, i have done mean imputation by using the following code. 

What changes i have to do to the following SAS code, (which i have got from a SAS blog), to make imputation with preceeding values.

thanks in advance 

 

/* Mean imputation: Use PROC STDIZE to replace missing values with mean */
proc stdize data=Have out=Imputed 
      oprefix=Orig_         /* prefix for original variables */
      reponly               /* only replace; do not standardize */
      method=MEAN;          /* or MEDIAN, MINIMUM, MIDRANGE, etc. */
   var Height;              /* you can list multiple variables to impute */
run;



 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Assuming your data is sorted by company_name

 

data have;
input company_name $ 1-17 time :yymmn6. investment;
infile datalines missover;
format time yymmn6.;
datalines;
3I Infotech Ltd. 200703 24.03
3I Infotech Ltd. 200706 27.29
3I Infotech Ltd. 200709      
3I Infotech Ltd. 200712 31.73
3I Infotech Ltd. 200803 33.39
3I Infotech Ltd. 200806 33.2
3I Infotech Ltd. 200809 32.46
3I Infotech Ltd. 200812 28.48
3M India Ltd.    200703 24.11
3M India Ltd.    200706      
3M India Ltd.    200709 39.14
3M India Ltd.    200712 35.99
3M India Ltd.    200803 39.03
3M India Ltd.    200806      
3M India Ltd.    200809 37.34
3M India Ltd.    200812 40.36
;

data Want;
   update have(obs=0) have;
   by company_name;
   output;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

PROC STDIZE is not the tool for this job. Post some sample data is you want a usable code answer.

srikanthyadav44
Quartz | Level 8

dear  

the format of the dataset is as follows

it is a panel data .

 

company_nametime investment
3I Infotech Ltd.20070324.03
3I Infotech Ltd.20070627.29
3I Infotech Ltd.200709 
3I Infotech Ltd.20071231.73
3I Infotech Ltd.20080333.39
3I Infotech Ltd.20080633.2
3I Infotech Ltd.20080932.46
3I Infotech Ltd.20081228.48
3M India Ltd.20070324.11
3M India Ltd.200706 
3M India Ltd.20070939.14
3M India Ltd.20071235.99
3M India Ltd.20080339.03
3M India Ltd.200806 
3M India Ltd.20080937.34
3M India Ltd.20081240.36

 

please suggest the SAS code for it. 

thanks in advance 

PeterClemmensen
Tourmaline | Level 20

Assuming your data is sorted by company_name

 

data have;
input company_name $ 1-17 time :yymmn6. investment;
infile datalines missover;
format time yymmn6.;
datalines;
3I Infotech Ltd. 200703 24.03
3I Infotech Ltd. 200706 27.29
3I Infotech Ltd. 200709      
3I Infotech Ltd. 200712 31.73
3I Infotech Ltd. 200803 33.39
3I Infotech Ltd. 200806 33.2
3I Infotech Ltd. 200809 32.46
3I Infotech Ltd. 200812 28.48
3M India Ltd.    200703 24.11
3M India Ltd.    200706      
3M India Ltd.    200709 39.14
3M India Ltd.    200712 35.99
3M India Ltd.    200803 39.03
3M India Ltd.    200806      
3M India Ltd.    200809 37.34
3M India Ltd.    200812 40.36
;

data Want;
   update have(obs=0) have;
   by company_name;
   output;
run;
srikanthyadav44
Quartz | Level 8

dear 

thanks a lot for your prompt response. 

Your SAS code is working excellently on the sample data posted in the query. 

 

In fact, I have the quarterly data from 200703 to 201803  having 45 observations for each companies and the panel dataset is having nearly 5000 companies. 

So, the total number of rows are more than 2 lakhs. the data is in a excel file. 

I am unable to change your code to run it with the imported excel file in SAS.

 please guide me making the required changes to the code sugggested by you. 

 

thanks in advance  

 

 

srikanthyadav44
Quartz | Level 8

thank Mr. 

the SAS code is working good. 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1321 views
  • 1 like
  • 2 in conversation