BookmarkSubscribeRSS Feed
GPatel
Pyrite | Level 9
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
4 REPLIES 4
Ksharp
Super User

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

Cynthia_sas
SAS Super FREQ

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

LHV
Calcite | Level 5 LHV
Calcite | Level 5

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,

GPatel
Pyrite | Level 9


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

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
  • 4 replies
  • 809 views
  • 0 likes
  • 4 in conversation