Help using Base SAS procedures

Proc Tabulate/Report

Reply
Contributor
Posts: 69

Proc Tabulate/Report

Help with Proc Tabulate/Report formatting output.
Data one;
input reason : $ year $ cas pct ;
cards;
XYZ 2010 68 51.9084
Others 2010 63 48.0916
XYZ 2011 169 62.3616
Others 2011 102 37.63
XYZ 2012 88 56.0510
Others 2012 69 43.9494
;
run;
How one create table like shown below with grid lines and exact column name either with proc report or proc tabulate?
                                2010       2011        2012
                               --------------------------------
  XYZ_Cnt                68        169            88
  XYZ_Pct                51.9       62.4         56.0
  Others_Cnt            63         102           69
  Others_PCt           48.0       37.6         43.9
My code shown below generates the output shown below, however, I would like to retain column name as shown above. 
Proc tabulate data=one order=data    ;
Class reason year;
classlev reason /style=<parent>[foreground=black];
Var cas pct;
table reason=' '*(cas='Xyz Count'*f=comma5. pct='Other Pct'*f=8.1), year=' ' / row=float;
Key Label sum=' '  ;
run;
Output from above code:
XYZXyz Count6816988
Other Pct51.962.456.1
Others Xyz Count6310269
Other Pct48.137.643.9
Super User
Posts: 10,020

Re: Proc Tabulate/Report

I think you should firstly change the data structure . after that it would be easy.

Data one;
input reason : $ year $ cas pct ;
cards;
XYZ 2010 68 51.9084
Others 2010 63 48.0916
XYZ 2011 169 62.3616
Others 2011 102 37.63
XYZ 2012 88 56.0510
Others 2012 69 43.9494
;
run;
data two;
 set one;
 length rea $ 50;
 rea=catx('_',reason,'cas');value=cas;output;
 rea=catx('_',reason,'pct');value=pct;output;
 keep rea year value;
run;
proc tabulate data=two order=data;
class rea year;
var value;
table rea=' ' , year=' '*value=' '*sum=' ' ;
run;

Ksharp

SAS Super FREQ
Posts: 8,862

Re: Proc Tabulate/Report

Hi:

  You say you want gridlines and you are using some ODS style= overrides in your syntax, but I do not see any ODS statements in your posted code. What is your destination of interest? HTML, RTF, PDF, SASReport (inside Enterprise Guide), CSV or ????

  That would be good information to know.

cynthia

Occasional Contributor LHV
Occasional Contributor
Posts: 15

Re: Proc Tabulate/Report

Hi,

I got it worked somehow , but not sure....let me know your openion plz.

data one;

input reason : $ year $ cas pct;

cards;

XYZ 2010 68 51.9084

Others 2010 63 48.0916

XYZ 2011 169 62.3616

Others 2011 102 37.63

XYZ 2012 88 56.0510

Others 2012 69 43.9494

;

run;

data two;

set one;

rea=catx('_',reason,'cas');value=cas;output;

rea=catx('_',reason,'pct');value=pct;output;

keep rea year value;

run;

proc sort data=two;

by rea year;

run;

proc tanspose data=two out=three(drop=_Name_);

id year;

by rea;

var value;

run;

result:


Thanks,

Contributor
Posts: 69

Re: Proc Tabulate/Report


Dear Cynthia, Ksharp, and LHV

   Your prompt and proposed soultion worked great.  Appreciate your time and interest.  I will use ODS style statements to display grids.

Regards,

Girish Patel

Ask a Question
Discussion stats
  • 4 replies
  • 242 views
  • 0 likes
  • 4 in conversation