I would like to display the frequency of a 2 level variable using proc report.
Below is my sample dataset. I would like to produce a proc report that looks at the number of each type within "Car" by Model and year.
So it might look like this;
year Model Car n_Car
2010 1 car 2
2010 1 truck 1
2010 2 car 1
2010 2 truck 2
Thanks!
data have;
input id year Model Car $;
A 2010 1 car
B 2010 1 car
C 2010 1 truck
D 2010 2 truck
E 2010 2 car
F 2010 2 truck
;;
Hi:
What code have you tried? Is there a reason, in particular that you want PROC REPORT, instead of TABULATE or FREQ?
cynthia
I am frustrated .Why would you want it be done by proc report .It is not advantage of REPORT.
data have; input id $ year Model Car $; cards; A 2010 1 car B 2010 1 car C 2010 1 truck D 2010 2 truck E 2010 2 car F 2010 2 truck ; run; proc report data=have nowd ; columns year y model m car n ; define year/group noprint; define y/computed; define model/group noprint ; define m/computed; define car/group; define n/'n_car'; compute before model; _y=year;_m=model; endcomp; compute n; y=_y;m=_m; endcomp; run;
Ksharp
Hi:
I understand KSharp's frustration. But, I'm not frustrated, just curious why the requirement to have REPORT do something (show a group item value on each row), when that is not the default behavior. The code samples below show different ways to accomplish your task. Not just with REPORT, but with TABULATE and FREQ, too.
cynthia
data have;
infile datalines dlm=' ';
input id $ Year Model Car $;
return;
datalines;
A 2010 1 car
B 2010 1 car
C 2010 1 truck
D 2010 2 truck
E 2010 2 car
F 2010 2 truck
;
run;
ods html file='c:\temp\show_methods.html';
proc print data=have;
title 'what the data looks like';
run;
proc report data=have nowd;
title 'proc report 1 - all the defaults';
column year model car n;
define year / group;
define model/ group;
define car / group;
define n / 'N_Car';
run;
proc report data=have nowd;
title 'proc report 2 - "fill in" empty rows for group var';
column year d_year model d_model car n;
define year / group noprint;
define model/ group noprint;
define d_year / computed 'Year';
define d_model / computed 'Model';
define car / group;
define n / 'N_Car';
compute before year;
holdyr = year;
endcomp;
compute before model;
holdmod = model;
endcomp;
compute d_year;
d_year = holdyr;
endcomp;
compute d_model;
d_model = holdmod;
endcomp;
run;
proc tabulate data=have;
title 'proc tabulate';
class year model car;
table year*model*car,
n='N_Car';
run;
proc freq data=have;
title 'proc freq';
tables year*model*car/list nocum nopercent;
run;
ods _all_ close;
title;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.