The SAS Output Delivery System and reporting techniques

Proc Tabulate Column Boarders

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Proc Tabulate Column Boarders

Hello everyone! I am not sure if it is possible, but I have the code below that is producing the output to rtf in the image attached titled capture.  I am wanting to produce the second image (capture2) with a boarder between column groups.  If this is possible, can you point me in the direction of what I need to be looking for?

 

PROC TABULATE
DATA=WORK.ENROLLED_DC S=[JUST=C];

	VAR TOTAL;
	CLASS location / ORDER=UNFORMATTED MISSING;
	CLASS highSchoolName /	ORDER=UNFORMATTED MISSING;
	TABLE 
		/* ROW Statement */
		highSchoolName={LABEL="" S=[CELLWIDTH=2.5in]} 
		all = 'Total'  ,
		/* COLUMN Statement */
		location={LABEL=""} *(TOTAL={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.6IN]}*f=comma6. TOTAL={LABEL=""} * RowPctN={LABEL="%" S=[CELLWIDTH=.6IN]}*f=PCTFMT. )
		all = 'Total'  *(TOTAL={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.6IN]}*f=comma6. TOTAL={LABEL=""} * RowPctN={LABEL="%" S=[CELLWIDTH=.6IN]}*f=PCTFMT. ) ;;
FORMAT location $LOCATION.;
RUN;
RUN; QUIT;

Capture.JPGCapture2.JPG

Accepted Solutions
Solution
‎09-22-2016 05:12 PM
Super User
Posts: 11,343

Re: Proc Tabulate Column Boarders

Posted in reply to laura6728

Sorry about the Total variable miss. I didn't see it as I NEVER put var statemets second and just couldn't see it...

 

Since I don't have your data this produces what I think your looking for.

Note that use of LABEL can affect what the styles are applied to.

 

ods html style=rtf;
data work.class;
   set sashelp.class;
   total=1;
run;

proc tabulate data=work.class;
   class age;
   class sex;
   classlev sex /s= [borderleftwidth=1 borderleftcolor=black borderleftstyle=solid];
   var total;
   keyword n / s=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid];
   table age all='Total', 
         sex="" *Total="" *
                            (n="#"*{ S=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid CELLWIDTH=.6IN]}*f=comma6. 
                             rowpctn="%"*{ S=[CELLWIDTH=.6IN]})
         all={label='Total' s=[ borderleftwidth=1 borderleftcolor=black borderleftstyle=solid]}*Total="" *
                            (n="#"*{ S=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid CELLWIDTH=.6IN]}*f=comma6. 

                             rowpctn="%"*{ S=[CELLWIDTH=.6IN]})
   /misstext=' ';
run; 

You might want to use a macro variable to hold the common style elements to make the code a tad easier to read and modify since the same code has to appear in different places to address the border of the Class variable, the header for the statistic  and the tabled values.

 

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Proc Tabulate Column Boarders

Posted in reply to laura6728

Which ODS style and destination are you using?

 

I'm not quite sure I believe that your posted tabulate code creates the first example. You have TOTAL in several places that I would expect to generate an error of undefined variable (Class or Var).

Contributor
Posts: 27

Re: Proc Tabulate Column Boarders

I am using the following style and destination code:

ods rtf file="\\PATH\SUMMARY.RTF"
startpage=no;

And yes, that code did create the output in the picture.  The TOTAL you are seeing is a variable named 'TOTAL', not total in the sense of a calcuation.  The variable TOTAL is what we use in our office for a variable that always =1 to do our calcuations on.

Solution
‎09-22-2016 05:12 PM
Super User
Posts: 11,343

Re: Proc Tabulate Column Boarders

Posted in reply to laura6728

Sorry about the Total variable miss. I didn't see it as I NEVER put var statemets second and just couldn't see it...

 

Since I don't have your data this produces what I think your looking for.

Note that use of LABEL can affect what the styles are applied to.

 

ods html style=rtf;
data work.class;
   set sashelp.class;
   total=1;
run;

proc tabulate data=work.class;
   class age;
   class sex;
   classlev sex /s= [borderleftwidth=1 borderleftcolor=black borderleftstyle=solid];
   var total;
   keyword n / s=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid];
   table age all='Total', 
         sex="" *Total="" *
                            (n="#"*{ S=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid CELLWIDTH=.6IN]}*f=comma6. 
                             rowpctn="%"*{ S=[CELLWIDTH=.6IN]})
         all={label='Total' s=[ borderleftwidth=1 borderleftcolor=black borderleftstyle=solid]}*Total="" *
                            (n="#"*{ S=[borderleftwidth=1 borderleftcolor=black borderleftstyle=solid CELLWIDTH=.6IN]}*f=comma6. 

                             rowpctn="%"*{ S=[CELLWIDTH=.6IN]})
   /misstext=' ';
run; 

You might want to use a macro variable to hold the common style elements to make the code a tad easier to read and modify since the same code has to appear in different places to address the border of the Class variable, the header for the statistic  and the tabled values.

 

Contributor
Posts: 27

Re: Proc Tabulate Column Boarders

That worked perfectly, thank you so much!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 397 views
  • 1 like
  • 2 in conversation