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

Hi

 

I am a builidng model in SAS enterprise miner by using logistic regression. This is the first time I am using miner and taken Titanic dataset from Kaggle. I have a column Age which has 19% missing value. Also, it has a column name called travelled class. I need to assign mean in place of missing value according to the class. For example, If people travelled in the first class I then I need to assign 37. If it is the second class then it is 29 and 24 if people travelled in third class.  

 

I tried to do in impute but it doesn't have an option to fill three values in the 'Age' column. Any suggestion about how to do this?

 

Regards,

Dhilip

 

1 ACCEPTED SOLUTION

Accepted Solutions
WendyCzika
SAS Employee

You would need to do it in a SAS Code node.  Here is example code to impute Age with its mean within each level of TravClass:


proc means data=&em_import_data mean stackodsoutput;
   class TravClass; /* change this to name of class variable, here and below */
   var age; /* change this to name of age variable, here and below */
   ods output summary=outmean;
run;

proc print data=outmean; run;

filename flow "&EM_FILE_EMflowSCORECODE";
filename pub "&EM_FILE_EMPUBLISHSCORECODE";

data _null_;
  set outmean end=last;
  file flow;
  if _n_=1 then do;
    put "if AGE = . then do;";
    put " if TravClass='" TravClass "' then ";
  end;
  else do;
    put " else if TravClass ='" TravClass "' then ";
  end;
  put " IMP_AGE = " mean ";";
  if last then do;
    put "end;";
    put "else IMP_AGE = AGE;";
  end;
run;

%em_copyfile(infref=flow, outfref=pub);

View solution in original post

1 REPLY 1
WendyCzika
SAS Employee

You would need to do it in a SAS Code node.  Here is example code to impute Age with its mean within each level of TravClass:


proc means data=&em_import_data mean stackodsoutput;
   class TravClass; /* change this to name of class variable, here and below */
   var age; /* change this to name of age variable, here and below */
   ods output summary=outmean;
run;

proc print data=outmean; run;

filename flow "&EM_FILE_EMflowSCORECODE";
filename pub "&EM_FILE_EMPUBLISHSCORECODE";

data _null_;
  set outmean end=last;
  file flow;
  if _n_=1 then do;
    put "if AGE = . then do;";
    put " if TravClass='" TravClass "' then ";
  end;
  else do;
    put " else if TravClass ='" TravClass "' then ";
  end;
  put " IMP_AGE = " mean ";";
  if last then do;
    put "end;";
    put "else IMP_AGE = AGE;";
  end;
run;

%em_copyfile(infref=flow, outfref=pub);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1802 views
  • 0 likes
  • 2 in conversation