From: Sdoof on 19 Dec 2009 12:52 Dear SAS Listers, I want to replace the missing values in my dataset with the corresponding median across each group define by another class variable: CountryCode The dataset looks like this CountryCode COMPANYAGE UK 10 UK . UK 12 FR 10 FR . US 20 US . US 10 I am using the following code but it is not doing what I want )i.e. it replaces all missing values with the median of the last country (US in the avove example) proc univariate data=DB; var CompanyAge ; class CountryCode ; output out= decile_CompanyAge_ pctlpts=50 pctlpre= CompanyAge_ ; run; data DB; set DB; if(_n_ eq 1) then set decile_CompanyAge_; by CountryCode; retain CompanyAge_50; ; run; data DB; set DB; by CountryCode; if missing(CompanyAge) THEN CompanyAge=CompanyAge_50; run; Thanks in advance :-)
From: data _null_; on 20 Dec 2009 09:03 On Dec 19, 11:52 am, Sdoof <olivier.vanpa...(a)gmail.com> wrote: > Dear SAS Listers, > > I want to replace the missing values in my dataset with the > corresponding median across each group define by another class > variable: CountryCode > The dataset looks like this > > CountryCode COMPANYAGE > UK 10 > UK . > UK 12 > FR 10 > FR . > US 20 > US . > US 10 > > I am using the following code but it is not doing what I want )i.e. it > replaces all missing values with the median of the last country (US in > the avove example) > > proc univariate data=DB; > var > CompanyAge > ; > class > CountryCode > ; > output out= > decile_CompanyAge_ > pctlpts=50 > pctlpre= > CompanyAge_ > ; > run; > > data DB; > set DB; > if(_n_ eq 1) then set decile_CompanyAge_; > by > CountryCode; > retain > CompanyAge_50; > ; > run; > > data DB; > set DB; > by CountryCode; > if missing(CompanyAge) THEN CompanyAge=CompanyAge_50; > run; > > Thanks in advance :-) Try this, it is much easier... data have; input CountryCode:$2. COMPANYAGE @@; cards; UK 10 UK . UK 12 FR 10 FR . US 20 US . US 10 ;;;; run; proc stdize reponly missing=median; by notsorted CountryCode; var Companyage; run; proc print; run;
|
Pages: 1 Prev: proc power question for McNemar test Next: proc power question for McNemar test |