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

Hi,

 

I'm using the following Freq statement to output proportion of tested persons with 5-10 days from exposure date. Follows is the code and the result.

 

proc freq data = merged;
tables Tested_Within_5to10days/norow nocol nofreq nocum out= Tested_Proportion;
title 'Proportion of contacts tested in the 5-10 day window of quarantine period';
run;

 

and this is the table:

 

mayasak_0-1658334137543.png

Is there a way that I get a more representable table with

  • A percent 16.7% for percent of total instead of 16.666666667
  • Change the heading "viewtable:work.tested_proportion(frequency...)"
  • Change the column names 
  • Remove a column such as the column with 1 an 2 or the Tested_within_5to10days.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
data prop (label='Proportion Tested');
   set proportion;
   percent= percent/100;
   format percent percent8.1;
   label
      percent = 'Text for percent label'
      count    = 'Text for count label'
   ;
run;

Makes permanent changes to the default label.

You can override the label in most procedure output by adding a LABEL statement in the body of the Procedure code using syntax just like that for the data step. Label and Format can be set in almost every procedure to something other than the defaults.

 

View solution in original post

12 REPLIES 12
mkeintz
PROC Star

I wonder whether you're confusing the normal displayed/printed output of proc freq results with a data viewer display of the output data set.  It's the latter you are showing.  But perhaps it's the earlier you want, commonly found in the Results Viewer tab.  It won't have row numbers displayed, and the percentage display will be more viewer-friendly.  You'll also get the title you specified.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

Most of what you request can be done in a data step using the Tested_proportion data set.

  • A percent 16.7% for percent of total instead of 16.666666667 - either change the format or modify the value and assign format. The percents in the result are your value so you could divide by 100, to get the decimal version of the percentage and assign a format like Percent8.1 if you want to see % signs.
  • Change the heading "viewtable:work.tested_proportion(frequency...)" - Label statement to change heading for a variable OR a data set label option to assign one to a data set:
    data somename (label='Desired data set label text');
       set sourcedataset;
    run;
  • Change the column names - Rename statement
  • Remove a column such as the column with 1 an 2 or the Tested_within_5to10days. - Not sure exactly what you mean. A "column" or variable is either in a data set or not, nothing conditional. An IF statement could test values of one or more variables and set variables to missing or delete an observation.
mayasak
Quartz | Level 8

Thank you ballardw,

I updated the percentage and changed the label by using this:

 

proc freq data = merged;
tables Tested_Within_5to10days/norow nocol nofreq nocum totpct outpct list out= Proportion;
format percent 8.1;
title 'Proportion of contacts tested in the 5-10 day window of quarantine period';
run;
data prop (label='Proportion Tested');
set proportion;
run;

I got this table:

mayasak_0-1658340934724.png

Much better but still I don't how to get the % sign format, I'm getting either 16.7 when I use '8.1' or 1667% when I use percent8.1 format, you mentioned using division by 100, how this could be done with the percent8.1 format?

Also, for changing the column name, I'm not sure where to add the renew statement?

Thank you

 

 

ballardw
Super User

Try

data prop (label='Proportion Tested');
   set proportion;
   percent= percent/100;
   format percent percent8.1;
run;
mayasak
Quartz | Level 8
Yesss it worked 🙂
Thank you
Just I couldn't change the "frequency count" and the "percent of total frequency" in the output table. Maybe it's not doable!
ballardw
Super User
data prop (label='Proportion Tested');
   set proportion;
   percent= percent/100;
   format percent percent8.1;
   label
      percent = 'Text for percent label'
      count    = 'Text for count label'
   ;
run;

Makes permanent changes to the default label.

You can override the label in most procedure output by adding a LABEL statement in the body of the Procedure code using syntax just like that for the data step. Label and Format can be set in almost every procedure to something other than the defaults.

 

mayasak
Quartz | Level 8
Thank you so much.
ballardw
Super User

Another approach to the display non-decimal values with % sign is a custom format.

 

data example;
   value = 68.1234567;
run;

proc format;
picture p2dec
low-high ='00009.99%';
run;

proc print data=example;
   format value p2dec.;
run;

The Picture format uses digit selectors where 9 indicates positions that will be displayed, using a 0 if no value in that position in the value and the % character is tacked onto the end. There are a number of options that are available as well. But this is not a standard supplied SAS format because the range of values you want might be different that SAS would create for a default. Also you can modify this for different ranges such as value of 0. Many people find things like 0.00% odd at best and possibly confusing. You could create custom ranges such that 0 (exactly 0) displays as a nicer 0% and 100 displays as 100% instead of 100.00%. Or even '<.01%' or similar which might be important if you have a number of very small values that would using either the Percent8.2 or my custom format display 0.00%. Nothing like showing 10 items of 0.00% with a total of 0.02% to confuse readers.

mayasak
Quartz | Level 8
Is there a way to widen the columns?
ballardw
Super User

@mayasak wrote:
Is there a way to widen the columns?

If you mean in the Viewtable window not with code so much. With the window open you can move your cursor to the top row with the labels/variable names and when placed correctly drag the column boundary.

If you have a Viewtable open you should have some appearance options on the VIEW menu that may be of interest such as Form view that will attempt to show one observation as a page. Note that the size of the page is that of the window. So you may have to 1) drag borders to get a larger window, 2) close the window, 3)reopen the window to use the larger size.

This assumes you are using a Display Manager or sometimes called Foundation, Base or PC SAS session.

 

mayasak
Quartz | Level 8
Hi mkeintz,
Thank you for the response.
No. I'm talking about the output data set.
sbxkoenk
SAS Super FREQ

Hello,

You can post-process the output data set from PROC FREQ

with PROC DATASETS and MODIFY statement.

 

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation | SAS 9.4 / Viya 3.5
Base SAS Procedures Guide
DATASETS Procedure
MODIFY Statement
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0ahh0eqtadmp3n1uwv55i2gyxiz.htm

 

Example 4: Modifying SAS Data Sets
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0mfav25learpan1lerk79jsp30n.htm


PROC DATASETS does not process the body of the data set (the data portion).
It's only dealing with the metadata portion.
So, dropping a columns CANNOT be done with PROC DATASETS (use PROC SQL or data step instead).


Cheers,
Koen

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 2569 views
  • 4 likes
  • 4 in conversation