- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 11-26-2020 03:48 PM
(2061 views)
I am trying to replace all missing values with Mode. I have tried PROC STDIZE but it does not support Mode as replacement method.
proc stdize data = have out = want reponly method = ???? ;
var _character_ ;
run;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It does have an IN method that allows you to build your most freq table and then use that drive your recoding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
can you please share some code to give me an idea
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Couple of minutes of searching found these, why don't you try some and see which one meets your needs. I unfortunately do not have the time to mock up example data and a solution at the moment. Someone else may offer an alternative option. The macro would be my starting approach.
https://www.listendata.com/2014/11/sas-macro-imputing-missing-data.html
https://stackoverflow.com/questions/26922779/fill-in-missing-values-with-mode-in-sas
Or something way more complicated:
https://stats.idre.ucla.edu/sas/seminars/multiple-imputation-in-sas/mi_new_1/
https://www.listendata.com/2014/11/sas-macro-imputing-missing-data.html
https://stackoverflow.com/questions/26922779/fill-in-missing-values-with-mode-in-sas
Or something way more complicated:
https://stats.idre.ucla.edu/sas/seminars/multiple-imputation-in-sas/mi_new_1/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let dsn= sashelp.heart; ods select none; ods output onewayfreqs=freq; proc freq data=&dsn ; table _character_ ; run; ods select all; data mode; set freq(drop=table); _level_=coalescec(of _character_); keep frequency _level_; run; data mode1; merge freq(keep=table) mode; run; proc sort data=mode1 out=mode2;by table frequency;run; data mode3; set mode2; by table; table=upcase(scan(table,-1,' ')); if last.table; drop frequency; run; data want; set &dsn ; array x{*} $ _character_; if _n_=1 then do; if 0 then set mode3; declare hash h(dataset:'mode3'); h.definekey('table'); h.definedata('_level_'); h.definedone(); end; do i=1 to dim(x); if missing(x{i}) then do;h.find(key:upcase(vname(x{i})));x{i}=_level_;end; end; drop i _level_ table; run;