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.

Answers were Sorted based on User's Feedback



Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / sattwik kumar

data b;
set a end=lastobs;
age_temp+age;
count+1;
if lastobs then
mean=age_temp/count;
run;

Is This Answer Correct ?    19 Yes 4 No

Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / 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

Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / chandrakanth

options firstobs=1 obs=26;
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;

proc sort data=a out=ab;
by age;
run;

options firstobs=13 obs=14;
data c;
set ab end=last;
sum_age+age;
if last then median=sum_age/2;
run;

we need observation 13 and 14 because total number of observations is n=26 when n is even we need to do mean of two observations n/2 and (n/2)+1 which is 13th and 14 th observations in this case.
let me know if you need more help... I'm still thinking about mode...will send once I get it

Is This Answer Correct ?    3 Yes 2 No

Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / paul

data b;
set a end=lastobs;
age_temp+age;
count+1;
if lastobs then
mean=age_temp/count;
if _n_=13 then
Median=Age; /*median is the mid value */
run;
proc sort data=b out=c;
by age;
run;
data d;
set c;
if first.age=0 and last.age=0 then
Mode=age;/*mode is the most repeated value*/
by age;
run;

Is This Answer Correct ?    3 Yes 9 No

Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / ravikumar

Answer:

data new;
set a end = last;
count+1;
age_n+age;
if last then do;
mean = round(((age_n)/(count)),.8);
median = ((count+1)/2);
end;
run;

By the above program we can calculate the mean and median.
lets us know me, if anybody find the logic for find mode

Is This Answer Correct ?    0 Yes 6 No

Can you calculate the mean, median and mode of the following data set using data step logic? Don&#..

Answer / +59+

651

Is This Answer Correct ?    2 Yes 11 No

Post New Answer

More SAS Interview Questions

What is SAS Information Map Studio and its purpose ?

2 Answers   SAS, TCS,


What is the pound sign used for the DATA _NULL_?

14 Answers  


I am preparing SAS Certified Advanced Programmer for SAS 9 in 2014. If anybody has the latest dumps for this exam, please mail me at dhiman.mukherjee@gmail.com

0 Answers  


how would you determine the number of missing or nonmissing values in computations? : Sas programming

0 Answers  


Why and when do you use proc sql?

0 Answers  






what is the difference between unique key and primary key? : Sas-di

0 Answers  


% let A=3+4 what is result

4 Answers   Satyam,


If you set a label in the data step and call a proc freq on the data, how do you display the data without the labels and just the variables.

1 Answers  


Hi, I have one dataset like id date ex: id date 1 13 1 13Oct2011 2 14 2 14Oct2011 3 15 3 15Oct2011 --->this is the current date here i want date format like 13Oct2011,14Oct2011 how we can modify the numeric to date format plz answer.

4 Answers  


what are some problems you might encounter in processing missing values? In data steps? Arithmetic? Comparisons? Functions? Classifying data? : Sas programming

0 Answers  


Difference between SAS STATA & SPSS?

0 Answers  


How necessary is it to be creative in your work?

0 Answers   Oracle,


Categories