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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

sfo
Quartz | Level 8 sfo
Quartz | Level 8
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.
sfo
Quartz | Level 8 sfo
Quartz | Level 8

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?

 

 

ballardw
Super User

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;
sfo
Quartz | Level 8 sfo
Quartz | Level 8

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 1924 views
  • 1 like
  • 3 in conversation