Hello,
I am stuck on step 3 of the following problem on a practice exam:
I was able to solve the first two steps, however, I am unable to solve the third based on the medians I have found. This is the code I have thus far:
Data cleandata36;
set cert.input36;
Group=upcase(Group);
if Group='A' or Group='B' then output;
Run;
Proc means data= cleandata36 MEDIAN maxdec=0;
class group;
var Kilograms;
Run;
Data results.output36;
set cleandata36;
Any help is appreciated, thank you!
please try the proc stdsize procedure, here the missing values within the group will be replaced with the method specified. Since you have the method as median, the missing values within the group will be replaced with the median of that group as we used by statement as group. The reponly option does help in replacing only the missing values with median. A very good procedure perfect for your requirement and it helps you avoid the step2.
PS it is an untested code as i am not sure of your, so please test and let me know if it is working. Per your response I am assuming that we need to keep only kilograms between 40 and 200 inclusive and then get the median value and then replace the missing values with median.
data nonmissing missing;
set cleandata36;
if 40<=kilograms<=200 then output nonmissing;
if missing(kilograms) then output missing;
run;
data cleandata36_2;
set nonmissing missing;
run;
proc sort data=cleandata36_2;
by group;
run;
proc stdize data=cleandata36_2 out=results.output36 method=median reponly;
var kilograms;
by group;
run;
Excellent suggestion from @Jagadishkatam . It doesn't get much simpler!
Hi @J_Moose
proc means data=cleandata36 median maxdec=0;
var Kilograms;
class group;
ways 1;
output out=cleandata36_median (drop=_:) median=median; /*create a dataset that contains the median for each group*/
run;
proc sort data=cleandata36; by group; run;
data results.output36;
merge cleandata36 cleandata36_median;
by group;
if Kilograms < 40 or Kilograms > 200 then Kilograms = median;
run;
if Kilograms < 40 or Kilograms > 200 AND group="A" then Kilograms=xxx;
else Kilograms < 40 or Kilograms > 200 AND group="B" then Kilograms=yyy;
data result.output36;
set cleandata36;
if group='A' then do;
if kilograms LT 40 or kilograms GT 200 then kilograms="79";
end;
else if group='B' then do;
if kilograms LT 40 or kilograms GT 200 then kilograms='89';
end;
run;
proc print data=result.output36;
run;
here is the code may helpful
data work.cleandata36;
set cert.input36;
group=upcase(group);
if group in ('A','B');
run;
proc means data=work.cleandata36 median;
class group; var kilograms;
run;
data results.output36;
set cleandata36;
if Kilograms < 40 or Kilograms > 200 then do;
if group='A' then kilograms=79;
else kilograms=89;
end;
run;
proc contents data=results.output36; run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.