- This proc means code is supposed to write the only the means of the observations
to an output dataset. What is wrong?
proc means mean data=original noprint;
var ht wt;
output out=ht_wt;
- Summarize the dataset dating.csv with
proc means and proc freq.
Use this script to create the dataset:
data dating;
infile "c:/datasets/dating.csv"
firstobs=13 dlm=',' dsd truncover;
input dum1-dum6 length $ satisf $ conflict $
clearexpct $ truth $ accom $;
* Need a value to count;
x = 1;
if dum1 = . then delete;
drop dum1-dum6 length;
label satisf='Relational Satisfaction'
conflict='Amount of Conflict'
clearexpct='Partner Makes Expectations Clear'
truth='Willingness to Tell Truth'
accom='Willingness to Accomodate Partner';
Ans: Use proc summary to summarize the
variables satisf and conflict:
proc means noprint;
class satisf conflict clearexpct truth accom;
var x;
output out=out;
proc print;
* You can also use proc freq;
proc freq data=dating;
table satisf * conflict;
proc freq data=dating;
table satisf * conflict * length;
- Translate the proc sql statements
in the Continents1 and Kids4 Examples into base SAS.
Ans: See the Continents2 and Kids5 Examples.
- Suppose that the dataset a contains the values
x = 23 51 76 98; the dataset b contains
x = 11 23 76 98 115.
Write a SAS script that contains (a) the union, and (b) the intersection of the two datasets.
How do you do this with proc sql? Ans:
* Using Base SAS;
data a;
input x @@;
datalines;
23 51 76 98
;
data b;
input x @@;
datalines;
11 23 76 98 115
;
data union;
merge a b;
by x;
proc print;
data intersect;
merge a (in=a) b (in=b);
by x;
if a and b;
proc print;
* Using proc sql;
proc sql;
select x from a
union
select x from b;
select x from a
intersect
select x from b;
- The following dataset contains the low and high temperatures (° F) at ORD airport
for the first ten days of January, 2014.
data temps;
input day low high @@;
datalines;
1 10 22 2 -1 21 3 -12 20 4 19 31
5 -3 29 6 -16 -2 7 -12 3 8 -6 17
9 -4 27 10 27 40
;
Use ods graphics to graph this data. Use this
article by Delwiche and Slaughter to help you set sgplot options:
Ans:
proc sgplot;
series x=day y=low / markers
markerattrs=(symbol=star color=green size=7mm);
series x=day y=high / markers;
xaxis type=discrete ;
yaxis label='Daily Temperatures' values=(-20 TO 45 BY 5);;
title 'Temperatures at Municipal Airport';
- Use ODS graphics to create a bar graph of this sales data ($ thousands):
data sales;
input region $ sales @@;
datalines;
North 345 East 732 South 643 West 1243
;
Ans:
proc sgplot;
vbar region / freq=sales;
* or;
proc sgplot;
vbar region / response=sales barwidth=0.5
stat=mean fillattrs=(color=magenta);
yaxis label='Total Sales';