Pekka
Pekka

Reputation: 2448

Suppress "Frequency" text in PROC FREQ

How can I get rid of the box inside the red circle

enter image description here

code:

data mydata;
input x y;
datalines;
    1 2
    3 4
    1 5
    3 2
;
run;

proc freq data=mydata;
    tables x*y /nopercent norow nocol;
run;

Upvotes: 3

Views: 4844

Answers (3)

DWal
DWal

Reputation: 2762

data mydata;
input x y;
datalines;
    1 2
    3 4
    1 5
    3 2
;
run;

/*Write new template to work folder */
ods path work.templat(update) sashelp.tmplmst(read);

/*Remove the "Frequency" header from the template */
proc template;
  edit Base.Freq.CrossTabFreqs;
    edit frequency;
      header="";
    end;
  end;
run;

proc freq data=mydata;
    tables x*y /nopercent norow nocol;
run;

Upvotes: 2

SRSwift
SRSwift

Reputation: 1710

As always with SAS there are multiple paths to the desirred result.

If you are willing to step away from proc freq you can achieve the required output using proc tabulate. This provides a simpler (and more concise) solution and does not require digging through the long and often confusing proc template documents.

proc tabulate data = mydata;
    /* Specify the variables to investigate */
    class x y; 
    table
        /* Put x in the rows suppress its title and add a total row */
        x = "" all = "Total", 
        /* Put y in the columns, request a total, request frequency count*/
        (y all = "Total") * n = "" / 
            /* Put "x" in the top left box */
            box = "x" 
            /* Put 0 instead of missing */
            misstext = "0"; 
run;

Upvotes: 2

Joe
Joe

Reputation: 63434

The only way I know how to do this is to edit the PROC FREQ template. Since 9.3 or so, PROC FREQ has been rewritten as a basic table via PROC TEMPLATE, which is nice because it lets us edit nearly all aspects of it.

What I do is right click on the Results tree header in display manager - like so: Results

Then select "Templates". This opens up the template list, which includes all templates you have installed (both style templates and table templates - most of the PROCs have a table template, though msot do not give you as much control as PROC FREQ does).

Then navigate to Sashelp.Tmplmst (Which is the major template store for most preinstalled templates), and open up Base, and then Freq. This gives you a list of table templates that make up PROC FREQ.

In your case, you want to open CrossTabFreqs, which is what you're producing (A crosstab). You could identify this by running ods trace on; then running your code; it will tell you in the log what the name of the template it's using is.

Open that and copy the contents of the template browser to the clipboard, then paste in a new window. We will modify it, save it in a temporary location, and use it.

Add to the top of the program this line:

ods path work.templat(update) sashelp.tmplmst(read);

This tells SAS two things: first, when we update or write to the template store, do that in work; and two, to look in work first then in sashelp for templates. This way when we create our new CrossTabFreqs template, it will come from work.

Now, look in the program for the location where it defines the Frequency block. This is what you want to modify, since this is the instructions for SAS telling it what to print when it is showing frequencies (as opposed to percents or whatnot). It will read as so:

  define Frequency;                                                       
     header = "Frequency";                                                
     format = BEST7.;                                                     
     label = "Frequency Count";                                           
     print;                                                               
     data_format_override;                                                
  end;    

You want to remove the header. You can do that one of two ways: either remove the header line entirely, or my preferred option, change it to

  define Frequency;                                                       
     header = " ";                                                
     format = BEST7.;                                                     
     label = "Frequency Count";                                           
     print;                                                               
     data_format_override;                                                
  end;    

Then run the entire program (including the ods path statement). Now, when you use PROC FREQ in this SAS session, it will have no text in the frequency table header.

Upvotes: 1

Related Questions