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:
Is there a way that I get a more representable table with
Thank you
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.
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.
Most of what you request can be done in a data step using the Tested_proportion data set.
data somename (label='Desired data set label text'); set sourcedataset; run;
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:
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
Try
data prop (label='Proportion Tested'); set proportion; percent= percent/100; format percent percent8.1; run;
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.
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 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.
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
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!
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.