BookmarkSubscribeRSS Feed
hnam
Calcite | Level 5

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

1 REPLY 1
Cynthia_sas
SAS Super FREQ

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 716 views
  • 0 likes
  • 2 in conversation