The SAS Output Delivery System and reporting techniques

Renaming Table name in Proc Tabulate

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 92
Accepted Solution

Renaming Table name in Proc Tabulate

Hi,

 

I am using Proc Tabulate in SAS 9.2 to create table for 8 variables. I have two questions:

 

Q1: Output window has Table 1, Table 2 .... Is there a way I can rename the Table 1 to name "BWT", Table 2 to "BSLD" ..

 

Q2. Is there a way I can use say a macro variable instead of tying for all the 8 variables. For example, if I have a variable say var = BWT BSLD METSITES CRP NLR ALBU LDH bTMB. So, can I do something like

 

Proc Tabulate;

class ADA4wk;;

Var &var*(N MEAN MIN MAX MEDIAN STD Q1Q3), ADA4wk?

 run;

 

**This is my original code**;
PROC TABULATE data=fdaada;
class ADA4wk;

VAR BWT BSLD METSITES CRP NLR ALBU LDH bTMB;
TABLE BWT * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE BSLD * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE METSITES * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE CRP * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE NLR * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE ALBU * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE LDH * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;
TABLE bTMB * (N MEAN MIN MAX MEDIAN STD Q1 Q3), ADA4wk;

run;


Accepted Solutions
Solution
‎06-28-2018 01:30 AM
Super User
Posts: 13,947

Re: Renaming Table name in Proc Tabulate

First the simple question:

Q2. Is there a way I can use say a macro variable instead of tying for all the 8 variables. For example, if I have a variable say var = BWT BSLD METSITES CRP NLR ALBU LDH bTMB. So, can I do something like

Proc Tabulate;
   class ADA4wk;;
   Var &var*(N MEAN MIN MAX MEDIAN STD Q1Q3), ADA4wk?

 run;

Other than the fact you do not want statistics on a VAR statement.

 

var &var. ;
table ( &var )*(N MEAN MIN MAX MEDIAN STD Q1Q3), ADA4wk?

You still must declare the VAR variables on a var statement. The table syntax for using multiple variables in the same role is

 

table (var1 var2 var3) *(n mean <etc>).  Without the parentheses only the last variable would be crossed with the statistics.

 

No clue for the Q1 directly in tabulate. Please describe the context of needing the table name in the results window.

View solution in original post


All Replies
Super User
Super User
Posts: 9,866

Re: Renaming Table name in Proc Tabulate

Use proc means to get the output:

proc means data=fdaata;
  var bwt bsld metsites crp nlr albu ldh btmb;
  output out=want n= mean= min=max= median= stddev= q1= q3= / autoname;
run;

Or you can use stackods to get it in a different layout:

https://blogs.sas.com/content/sgf/2015/07/17/customizing-output-from-proc-means/

 

Please also note, avoid coding ALL IN CAPITALS as it is shouting.  And use the code window - its the {i} above post area.

Solution
‎06-28-2018 01:30 AM
Super User
Posts: 13,947

Re: Renaming Table name in Proc Tabulate

First the simple question:

Q2. Is there a way I can use say a macro variable instead of tying for all the 8 variables. For example, if I have a variable say var = BWT BSLD METSITES CRP NLR ALBU LDH bTMB. So, can I do something like

Proc Tabulate;
   class ADA4wk;;
   Var &var*(N MEAN MIN MAX MEDIAN STD Q1Q3), ADA4wk?

 run;

Other than the fact you do not want statistics on a VAR statement.

 

var &var. ;
table ( &var )*(N MEAN MIN MAX MEDIAN STD Q1Q3), ADA4wk?

You still must declare the VAR variables on a var statement. The table syntax for using multiple variables in the same role is

 

table (var1 var2 var3) *(n mean <etc>).  Without the parentheses only the last variable would be crossed with the statistics.

 

No clue for the Q1 directly in tabulate. Please describe the context of needing the table name in the results window.

Frequent Contributor
Frequent Contributor
Posts: 92

Re: Renaming Table name in Proc Tabulate

Thanks will try your solution to Q1.

For my Q2 it’s more for convenience so that I can easily go to the results of the table if interest otherwise I have to scroll on the pages.
Frequent Contributor
Frequent Contributor
Posts: 92

Re: Renaming Table name in Proc Tabulate

Thanks it is working.

 

I have one more quick question. In another analysis I have a code like this:

 

proc tabulate data=perflags;
class Group2;
var &var;
table (&var)*(N MEAN MIN MAX MEDIAN STD Q1 Q3), Group2;
by Group1;
run;

It is producing the output and displays the values in group1 on top of the table,  but the font of the values in group1 is really small. Is there a way I can increase it?

 

 

Super User
Posts: 13,947

Re: Renaming Table name in Proc Tabulate

Text appearance for things like the BY variables by default is ODS style dependent.

 

So you could experiment with other SAS supplied ODS styles, delve in the joys of Proc Tabulate and modify a style to create your own (style element to modify would be "style Byline") style and use that or work with the TITLE statement and byline options.

The first two are more in the once done you need not think about if you always want all bylines to have the new appearance.

 

Example with title and byline options:

/* create some example data*/
proc sort data=sashelp.class out=work.class;
   by sex;
run;

/* turn off the default by line*/
options nobyline;
/* use a title statement to modify the text of the byline*/
title h=20pt '#byline';
proc tabulate data=work.class;
   class  sex age;
   var height;
   classlev sex/style=[foreground=red];
   by sex ;
   table age,
         height* mean
   ;
run; title;
/* reset the byline option for other procs*/
options byline;
Frequent Contributor
Frequent Contributor
Posts: 92

Re: Renaming Table name in Proc Tabulate

Thanks a lot for the quick solution. It works perfectly.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 172 views
  • 1 like
  • 3 in conversation