BookmarkSubscribeRSS Feed
Lissa1
Calcite | Level 5

Hello!

We need to recreate a table. We have come up with this, but we need to add labels (e.g. T, BRJ) instead of 1, 2 and 3. We also want to display the n= .. at the top row.

 

Any advice?

 

Thank you in advance.

2 REPLIES 2
ballardw
Super User

How are you building the table?

 

The basic approach would typically be to have a custom format that displays the desired text for the values of the variable.

The format code might look like

Proc format;
   value varlabel
1 ='T'
2 ='BRJ'
3 ='Other'
;
run;

Then in which ever code is generating the table you would have a Format statement to tell SAS to use that format to display the format values for that variable. Something like

 

Format acrossvariable varlabel. ;

 

It isn't possible to tell if your 1, 2, 3 are numeric or character. I have assumed the values are numeric. If they are character the the format name would have to have a $ in the Value statement in the definition and in the Format statement associating the value. The values on the left of the = in the Value statement should also be in quotes.

 

We really need to know how the report is made to know if it is possible to insert a row with N. And by "in the top row" do you mean in the column heading like "1 (n=17)" or something else? That is likely going to mean significant changes to your existing code.

 

Copy the procedure code that generates the table from your editor and paste into a text or code box opened on the forum with either the </> or "running man" icons at the top of the message window.

Cynthia_sas
SAS Super FREQ

Hi:
How you change the labels will depend on the procedure or method you're using to create the table. If you were using PROC REPORT (for example) you could just add a spanning header with your "extra" information. If you are using PROC TABULATE, sometimes it is possible to relabel spanning headers to contain other information. Although it is useful to see your output, it would be more useful to see the code you've used to create this output and to also have some data so that people could run the code on their own. Without data and without code, people need to guess what your data structure is and what your code is and to run any code or make any suggestions, they have to make some sample data and they have to write all the code.
There's not a direct method to get the N statistic in a spanning header, however, there are always macro variables that are one possible technique. Your output looks similar to PROC TABULATE output. Here's an example that uses SASHELP.CARS:

%let ovcnt = 428;
  
proc tabulate data=sashelp.cars;
  class drivetrain;
  var mpg_highway mpg_city enginesize;
  table mpg_highway mpg_city enginesize,
        drivetrain="N=&ovcnt"*(n mean StdDev);
run;

Note that in my example, the &OVCNT macro variable holds my count or overall N which I looked up manually to find out it was 428. There are automated ways to get the N -- reading from dictionary tables or using PROC CONTENTS. But I just used a hard-coded value for the macro variable.

Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 519 views
  • 0 likes
  • 3 in conversation