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

what are the best practices to process the large data sets in sas programming? : Sas-administrator

529


how do you pull data from equifax?tell me the process?

1371


for whom is sas data integration studio designed? : Sas-di

551


What is your favorite all time computer book? Why?

2044


What are the prime responsibilities of data integration administrator? : Sas-di

583






which date functions advances a date time or date/time value by a given interval? : Sas programming

528


What is the difference between class statement and by statement in proc means?

638


Given an unsorted data set, how to read the last observation to a new data set?

828


What are the advantages of using sas?

603


what is function of retain statment

1516


what are _numeric_ and _character_ and what do they do? : Sas programming

672


what is hierarchy flattening? : Sas-di

614


if a variable contain dates like "2015/01"---"2015/12" (yymm) ,How to add day to those dates,if them month is jan then 31 if the month is feb then 28 so on ...

934


Differentiate between ceil and floor functions.

650


what do the sas log messages "numeric values have been converted to character" mean? What are the implications? : Sas programming

684