BookmarkSubscribeRSS Feed
supersonic
Calcite | Level 5

Hi I need to replace all missing values in a dataset with respective mean.

Find the sample i wrote.

%macro replace_missing(dataset);

      proc means data=&dataset mean ; ;

            output out=t (drop=_type_ _freq_) mean=/autoname;

    run;

      proc transpose data=t out=tr;

      run;

data _null_;

      set Tr end=last ;

      call symput('mean'||left(_n_),col1);

      if last then call symput('maxi', _n_);

            /* x=left(_N_) */;

            /* put _N_ maxi last x ; */;

run;

data &dataset;

      set &dataset;

      array num(*) _numeric_;

            %do n=1 %to &maxi;

                  if num(&n)=. then num(&n)= &&mean&n;

            %end;

run;

%mend;

%replace_missing(drop_missing);

run;

But this is not working..

Please help

6 REPLIES 6
BrunoMueller
SAS Super FREQ

supersonic

Proc STANDARD will do this for you, see code sample below.

data someTest;
  infile cards dlm=",";
 
input
    v1
    v2
  ;
cards;
1,100
2,.
3,3
4,.
.,20
;

proc standard data=someTest out=sometest2 replace print;
run;

proc print data=someTest;
run;

proc print data=someTest2;
run;

proc means data=someTest2;
  var v:;
run;
Murray_Court
Quartz | Level 8

Works well with this dataset:

data one;

input thing;

datalines;

100

101

.

103

104

105

;

Can you give the log or the dataset you tried to use it with?

supersonic
Calcite | Level 5

Hi Murray

Its a very huge dataset.

My aim is to replace all the missing values with the corresponding mean value

LinusH
Tourmaline | Level 20

As stated by https://communities.sas.com/people/Murray_Court, attach a log or describe in more detail what it is that does not work...

Data never sleeps
jakarman
Barite | Level 11

Base SAS(R) 9.4 Procedures Guide (PROC standard replacing missing by mean) == Bruno-s  ==

The advantage of this procedure is it is part of SAS/Base Procs

If it should be more advanced like being in the Eminer processing, That one is using

SAS/STAT(R) 12.3 User's Guide (Proc MI) .

You nee to be licnesed for that. 

---->-- ja karman --<-----
sandyming
Calcite | Level 5

proc stdize data=old out=new missing=mean reponly;
  var _numeric_;
run;


You can also calculate the median first, then read values from a second data set

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 6 replies
  • 8270 views
  • 1 like
  • 6 in conversation