Help using Base SAS procedures

Proc Report Quest

Reply
Occasional Contributor
Posts: 7

Proc Report Quest

Dear SASeers

I am trying to generate a table using Proc Report and it has to look this:

Using the code below I am getting No/Yes below each other and not across.

I could get the exact thing using Proc Tabulate but not with Report.

My code is:

proc report data=clin1.history nowd  headline ;

column smoking N alcohol N;

define smoking / n 'Smoking' group width=5;

define smoking / across group width=3;

/*define n / width=5 ;*/

define alcohol / n 'Alcohol'group width=5;

define alcohol / group width=3;

/*define n / width=5 ;*/

format smoking alcohol $ynfmt.;

run;

 

Smoking

Alcohol

No

Yes

No

Yes

4

16

17

3

Thanks in advance

hnam

SAS Super FREQ
Posts: 8,743

Re: Proc Report Quest

Hi:

  This question would be easier to answer if we knew what your data looked like. Your PROC REPORT statements are incorrect...you can't have the same variable defined with ACROSS, GROUP and an ANALYSIS (N) usage. So even though PROC REPORT doesn't give you a message in the log, your syntax is confusing. Also, your syntax includes references to LISTING only options (such as HEADLINE and WIDTH= that would not work for ODS HTML, ODS PDF or ODS RTF).

  The code for me produced exactly the same table in TABULATE vs REPORT. PROC TABULATE provides the N statistic automatically for CLASS variables. For PROC REPORT, the comma operator is used to place a statistic or a statistic based on another variable "underneath" the across variable values. So, the second PROC REPORT step shows how to get the MEAN of HEIGHT and WEIGHT "underneath" each unique value for the SEX variable.

cynthia

data history (keep= name smoking alcohol);

  set sashelp.class;

  ** make some fake data;

  if age lt 13 then smoking = 'No ';

  else smoking = 'Yes';

  if substr(name,1,2) le 'Je' then alcohol = 'No ';

  else alcohol='Yes';

run;

   

ods listing;

proc print data=history;

  var name smoking alcohol;

run;

ods listing close;

  

ods html file='c:\temp\across.html';

 

proc tabulate data=history;

title 'TABULATE method';

  class smoking alcohol;

  table smoking alcohol;

  keylabel n=' ';

run;

  

proc report data=history nowd ;

title 'REPORT method';

  column smoking,n alcohol,n;

  define smoking / across ;

  define alcohol / across;

  define n / ' ';

run;

   

proc report data=sashelp.class nowd;

  title 'Showing different use of the comma operator';

  column age sex,(height weight);

  define age / group;

  define sex / across 'Gender Averages by Age';

  define height / mean 'Height' f=comma6.2;

  define weight / mean 'Weight' f=comma6.2;

run;

ods html close;

title;

Ask a Question
Discussion stats
  • 1 reply
  • 179 views
  • 0 likes
  • 2 in conversation