You are on page 1of 4

Previous Year Question Paper Solutions

2.
a.
data mpg;
input speed car @@;
do track = 1 to 2;
do rep = 1 to 3;
input MPG @@;
output;
end;
end;
cards;
70 1 19.3 18.3 20.3
70 2 19.0 21.7 20.2
70 3 16.5 16.2 15.2
70 4 16.3 16.6 16.8
55 1 18.9 18.1 19.2
55 2 19.4 18.7 20.7
55 3 20.5 19.4 18.9
55 4 17.1 16.5 17.2
40 1 22.6 24.8 22.2
40 2 23.2 20.9 20.6
40 3 18.3 17.8 19.3
40 4 21.8 21.7 19.5
;
run;

20.8
18.4
14.7
17.6
20.4
21.9
20.1
18.0
25.3
22.7
20.4
22.7

21.2
19.7
16.4
18.0
21.7
23.0
20.0
19.4
26.1
24.0
19.0
20.7

20.2
19.4
17.0
18.9
21.0
21.0
20.5
18.3
27.1
21.9
20.0
22.6

proc print data = MPG;


run;
proc means data=MPG;
class speed track;
var MPG;
run;

b.
data age;
input age name $;
if age lt 20 and not missing(Age) then AgeGroup =1;
if age ge 20 and age lt 40 then Agegroup =2;
if age ge 40 and age lt 60 then Agegroup =3;
if age ge 60 then Agegroup =4;
datalines;
21 Agatha
35 Conan
. Andrew
45 William
65 Raymond
. Steve
39 Raven
34 Peter
18 Laura
17 Daniel

. Julia
68 Emma
47 Avery
16 Finely
25 Shane
38 Drew
;
proc print data =age;
run;

c.
data survey;
input ID $ 1-3 Gender $ 5 Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5
$;
infile datalines missover;
datalines;
001 M 23 28000 5 2 1 2 3
002 F 55 76123 4 5 2 1 1
003
38 . 4 2 2 2 1
004 F . 128000 3 3 2 2 4
005 M 22 23060 4 3 3 4 2
006 M 63 90000 2 3 5 4 3
007 F 45 76100 5 3 4 3 3
008 M . 28000 1 2 2 2 3
009 55 76123 4 5 2 2 2
010 M 38 36500 2 3 2 3 1
011 F 67 128000 4 3 2 2 5
012 M 22 23060 2 2 1 3 2
013 . . 3 4 4 5 4
014 F 45 76100 4 1 1 2 2
;
run;
proc print data = survey;
run;
proc format;
value $gender 'M' ='Male' 'F'
value age low-29 = 'Less than
value $likert '1' = 'Strongly
'4' = 'Agree' '5' = 'Strongly
run;
proc freq data =survey;
table gender*ques1;
format gender $gender.;
format Ques1-Ques5 $likert.;
run;
proc means data=survey mean;
class age;
format age age.;
var age;
run;

= 'Female' '' = 'Not Entered';


30' 30-50 = '30 to 50' 51-high = '51+';
Disagree' '2'= 'Disagree' '3' = 'No Opinion'
Agree';

3.
a.
data pharma;
set Pharmasales;
run;
proc gchart data=pharma;
vbar region/ sumvar=totalsales subgroup=division;
run;
proc gchart data=pharma;
vbar month/ sumvar=totalsales discrete subgroup=region;
run;
proc gchart data=pharma;
pie region/ sumvar=totalsales;
run;

b.

> attach (AQ)


> par(mfrow=c(3,1))
> hist(Solar.R, col=c(1,2))
> plot(Solar.R, Wind, col="green")
> hist(Wind, col=c(2,2))
> plot(Temp, Wind, col="green")

(Same thing follows)

4.
Macros: Instead of Stores data, the below data is taken. Macro code is in bold.
data survey;
input ID $ 1-3 Gender $ 5 Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
infile datalines missover;
datalines;
001 M 23 28000 5 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 38 . 4 2 2 2 1
run;
data survey_1;
input ID $ 1-3 Gender $ 5 Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
infile datalines missover;
datalines;
006 M 23 28000 5 2 1 2 3
005 F 55 76123 4 5 2 1 1

004 M 38 56789 4 2 2 2 1
run;
proc print data = survey;
run;
proc format;
value $gender 'M' ='Male' 'F' = 'Female' '' = 'Not Entered';
value $likert '1' = 'Strongly Disagree' '2'= 'Disagree' '3' = 'No Opinion' '4' = 'Agree' '5' = 'Strongly Agree';
value age low-29 = 'Less than 30' 30-50 = '30 to 50' 51- high = '51+';
run;
proc freq data =survey;
table gender*ques1;
format gender $gender.;
format Ques1-Ques5 $likert.;
run;
proc means data=survey;
class age;
format age age.;
var age;
run;

%macro gen(a,b);
data &a;
set &a &b;
run;
%mend gen;
%gen(survey,survey_1)

- appends survey_1 data into survey

%macro gen1(age,c,d);
data &c;
set &d (where=(age > &age));
run;
%mend gen;
%gen1(50,survey_2,survey)

- appends only those data from survey > 50

%macro gen(a);
proc means data = &a;
class age;
var salary;
run;
%mend gen;
%gen(survey_1);

- mean of salary by age

You might also like