Help using Base SAS procedures

proc report

Reply
Frequent Contributor
Posts: 104

proc report

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

;;

SAS Super FREQ
Posts: 8,683

Re: proc report

Hi:

What code have you tried? Is there a reason, in particular that you want PROC REPORT, instead of TABULATE or FREQ?

cynthia

Grand Advisor
Posts: 9,463

Re: proc report

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

SAS Super FREQ
Posts: 8,683

Re: proc report

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;

Ask a Question
Discussion stats
  • 3 replies
  • 184 views
  • 0 likes
  • 3 in conversation