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
I have a SCD Type 2 Dimention for Location In which A Sales Office in Having two Surrogate Keys just because of the change in it's Sales Group. SKey SalesGroup Sales Office BeginDate EndDate 280 SG1 SO1 01APR2000 01APR2010 281 SG2 SO1 02APR2010 31MAR2999 Now while loading the Fact, the Lookup ir returning SKey 280 for records before and after 01APR2010. I am not able to give WHERE condition in the Lookup Properties (TranDate between BeginDate and EndDate). Please help.
What system options would you use to help debug a macro? : sas-macro
What is factor analysis?
What are the differences between proc means and proc summary?
Can you execute macro within another macro? : sas-macro
How do you add a number to a macro variable? : sas-macro
How will you use the WHO Drug Dictionary for Reporting Clinical Trials?
What does P-value signify about the statistical data?
Give an example where SAS fails to convert character value to numeric value automatically?
What are the ways in which macro variables can be created in sas programming?
how the sas basic syntax style described? : Sas-administrator
what is operational data and operational system? : Sas-di
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
Approximately what date is represented by the SAS date value of 730?
What are the five ways to do a table lookup in sas? : sas-grid-administration