Can you calculate the mean, median and mode of the following data set
using data step logic? Don't use any function or procedure.
data a;
input age @@;
datalines;
22 32 32 32 43 23 24 56 45 54 28 29 27 26 25 28 30 20 18 37 36 47 46
56 19 20
;
run;
I have calculated the mean which i have posted in the answer section.

Answer Posted / rg

data temp;
input age @@;
cards;
8 7 7 2 67 9 7 7 1 2 45 34 22 45 23 8 34 23
run;


proc sort data=temp; by age ;run;

data a(keep = median mode_age mean);
last_age=age;
retain max_cnt mode_age median;
set temp end=lastobs nobs=n;
by age;
age_temp + age;

/*Median */
if mod(n,2) = 1 and _n_ = (n+1)/2 then do ;median=age; end;
if mod(n,2) = 0 and _n_ = (n+2)/2 then do ;median=(age + last_age)/2; end;

/*Mean*/
if lastobs then do mean=age_temp/n ; end;

/*Mode */
if first.age then cnt =1; else cnt+1;
if last.age then lst_cnt=cnt;
if lst_cnt > max_cnt then do; max_cnt = lst_cnt; mode_age = age;end;


if lastobs then output;
run;

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do we follow ADAM in analysis dataset development?How? Usually which version? Why is it necessary?

1914


What are the different operating system platforms in which we can use sas? : sas-grid-administration

591


: and & modifiers.

860


how will you locate the sas platform applications? : Sas-bi

584


Can you suggest us materials for sdtm mapping?

4039






is data integration and etl programming is same? : Sas-di

576


How will you react when, while consulting a SAS documentation manual to get an answer to a problem, someone says hey, I thought you were supposed to know all that stuff already, and not have to look it up in a book?

1944


What does P-value signify about the statistical data?

853


what are the scrubbing procedures in sas? : Sas programming

831


Explain the purpose of substr functions in sas programming.

563


what is information maps?

1616


For what purposes have you used sas macros? : sas-macro

540


What are the features of base sas system?

613


What makes sas stand out to be the best over other data analytics tools?

589


what is the function of catx syntax? : Sas-administrator

652