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

Hello

I am trying to create multiple one-way freq tables via proc tabulate.

For each table I want to create a separate title.

Why is it not working???

proc tabulate data=sashelp.heart;
  class chol_status bp_status  sex;

  title 'chol_status field';
  table chol_status='' All,n='people' pctn='%people'*f=pctfmt./box='cholesterol';

  title 'bp_status field';
  table bp_status='' All,n='people' pctn='%people'*f=pctfmt./box='BP ';

  title 'sex field';
  table sex='' All,n='people' pctn='%people'*f=pctfmt./box='Gender';
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
singhsahab
Lapis Lazuli | Level 10

Hi Robin,

 

In place of title you can use pretext style options in table statement. 

 

proc tabulate data=sashelp.heart;
  class chol_status bp_status  sex;

  table chol_status='' All,n='people' pctn='%people'*f=pctfmt./box='cholesterol' 
   style=[pretext='chol_status field'];
   
  
  table bp_status='' All,n='people' pctn='%people'*f=pctfmt./box='BP '
  style=[pretext='bp_status field'];;
   

  table sex='' All,n='people' pctn='%people'*f=pctfmt./box='Gender'
  style=[pretext='sex field'];
run;

Thanks 🙂 

View solution in original post

5 REPLIES 5
singhsahab
Lapis Lazuli | Level 10

Hi Robin,

 

In place of title you can use pretext style options in table statement. 

 

proc tabulate data=sashelp.heart;
  class chol_status bp_status  sex;

  table chol_status='' All,n='people' pctn='%people'*f=pctfmt./box='cholesterol' 
   style=[pretext='chol_status field'];
   
  
  table bp_status='' All,n='people' pctn='%people'*f=pctfmt./box='BP '
  style=[pretext='bp_status field'];;
   

  table sex='' All,n='people' pctn='%people'*f=pctfmt./box='Gender'
  style=[pretext='sex field'];
run;

Thanks 🙂 

Kurt_Bremser
Super User

title is a global statement which is executed immediately when encountered in the code.

The proc tabulate code is fetched until a step boundary is encountered, and executed then.

So your code is equivalent to this:

title 'chol_status field';
title 'bp_status field';
title 'sex field';

proc tabulate data=sashelp.heart;
  class chol_status bp_status  sex;

  table chol_status='' All,n='people' pctn='%people'*f=pctfmt./box='cholesterol';

  table bp_status='' All,n='people' pctn='%people'*f=pctfmt./box='BP ';

  table sex='' All,n='people' pctn='%people'*f=pctfmt./box='Gender';
run;

You need to do three separate proc tabulates.

ballardw
Super User

"Not working" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

 

Since your output does consist of three separate tables I have to guess that your complaint is that you get the LAST defined title for all three tables. That is way the TITLE statement works for any procedure with multiple tables; they all get the same title.

 

You can use Style= Pretext to place different text before each table

title;/* turn off existing titles*/
proc tabulate data=sashelp.heart;
  class chol_status bp_status  sex;

  table chol_status='' All,n='people' pctn='%people'*f=pctfmt.
   /box='cholesterol' style=[Pretext='chol_status field'];

  table bp_status='' All,n='people' pctn='%people'*f=pctfmt.
   /box='BP ' style=[Pretext='bp_status field'];

  table sex='' All,n='people' pctn='%people'*f=pctfmt.
   /box='Gender' style=[Pretext='sex field'];
run;
Ronein
Meteorite | Level 14

When I write "not working" and I said that the problem is with titles.

You could run it and see it .

 

ballardw
Super User

@Ronein wrote:

When I write "not working" and I said that the problem is with titles.

You could run it and see it .

 


Yes, but you did not actually include what the output should look like. So I was guessing at the desired result.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 911 views
  • 4 likes
  • 4 in conversation