BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
laura6728
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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).

laura6728
Obsidian | Level 7

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.

ballardw
Super User

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.

 

laura6728
Obsidian | Level 7

That worked perfectly, thank you so much!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1127 views
  • 1 like
  • 2 in conversation