<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Format of Proc Freq output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652070#M195721</link>
    <description>&lt;P&gt;Please see the output image below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot - 5_30_2020 , 11_20_51 PM a.png" style="width: 443px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40188iCFD09E6719BD7410/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot - 5_30_2020 , 11_20_51 PM a.png" alt="Screenshot - 5_30_2020 , 11_20_51 PM a.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason in the Frequency column I am getting lines with decimal point and number.&amp;nbsp; xxxxx.4 for instance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following is the code used to generate what's shown above:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq
data=sas_3.variable_values_separate_runs nlevels order=freq page;
where Indicator = "i_21504a";
tables
indicator * range
/ nocum nocol norow sparse crosslist missprint format=15.0;
weight number_weighted_yes / zeros;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone think of a way to avoid those decimal places in the Frequencies column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, can anyone suggest a way of showing ONLY ONE decimal place in the Percent column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 31 May 2020 05:42:08 GMT</pubDate>
    <dc:creator>NKormanik</dc:creator>
    <dc:date>2020-05-31T05:42:08Z</dc:date>
    <item>
      <title>Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652070#M195721</link>
      <description>&lt;P&gt;Please see the output image below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot - 5_30_2020 , 11_20_51 PM a.png" style="width: 443px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40188iCFD09E6719BD7410/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot - 5_30_2020 , 11_20_51 PM a.png" alt="Screenshot - 5_30_2020 , 11_20_51 PM a.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason in the Frequency column I am getting lines with decimal point and number.&amp;nbsp; xxxxx.4 for instance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following is the code used to generate what's shown above:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq
data=sas_3.variable_values_separate_runs nlevels order=freq page;
where Indicator = "i_21504a";
tables
indicator * range
/ nocum nocol norow sparse crosslist missprint format=15.0;
weight number_weighted_yes / zeros;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone think of a way to avoid those decimal places in the Frequencies column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, can anyone suggest a way of showing ONLY ONE decimal place in the Percent column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 05:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652070#M195721</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2020-05-31T05:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652071#M195722</link>
      <description>&lt;P&gt;Try by adding next statement to the proc, just before the RUN;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format count 8.;

or 

format _freq_ 8.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 31 May 2020 06:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652071#M195722</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-05-31T06:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652081#M195724</link>
      <description>&lt;P&gt;Managed to get Frequency to format with NO decimal places.&amp;nbsp; By using list, as opposed to crosslist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still can't get Percent to a single decimal digit.&amp;nbsp; No way no how.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ought to be easier....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 09:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652081#M195724</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2020-05-31T09:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652088#M195728</link>
      <description>&lt;P&gt;Is the weight variable&amp;nbsp;&lt;STRONG&gt;NUMBER_WEIGHTED_YES&amp;nbsp;&lt;/STRONG&gt;an integer?&lt;/P&gt;
&lt;P&gt;Shouldn't weight fraction create, in some cases, a counting fraction?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 13:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652088#M195728</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-05-31T13:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652091#M195729</link>
      <description>&lt;P&gt;You can modify the formats in PROC FREQ tables by using PROC TEMPLATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are some examples in this paper by Kathryn McLawhorn:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings17/SAS0404-2017.pdf" target="_self"&gt;Tables and Graphics that will FREQ You Out&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;See page 3 for an example of changing the format of Percent in a one-way or LIST table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 15:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652091#M195729</guid>
      <dc:creator>Watts</dc:creator>
      <dc:date>2020-05-31T15:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Format of Proc Freq output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652101#M195734</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;C&lt;/SPAN&gt;&lt;SPAN&gt;an anyone think of a way to avoid those decimal places in the Frequencies column?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From the Log&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;NOTE: The FORMAT= option has no effect in a CROSSLIST table.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Consider that you are using FREQ to only count and computed percentages within a group.&amp;nbsp; That is a very small subset of FREQs analytic capability but you&amp;nbsp;don't have complete control over the presentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose you preprocess the data a little and use a different procedure that has more control over presentation.&amp;nbsp; That would be either proc REPORT or TABULATE, followed up by PRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider the case of TABULATE.&amp;nbsp; You will need an analytic variable for weighted statistical processing (tabulate does not do weighted N).&amp;nbsp; I use the surrogate variable UNITY (=1) to replicate weighted N counting.&amp;nbsp; You also want to have the rows ordered by FREQs 'freq' which corresponds to a weighted analysis result in TABULATE.&amp;nbsp; TABULATE only provides for ordering according to classification variables, you can force a custom order using / ORDER=DATA if your pre-processing sorts the data in the desired order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Tabulate can NOT produce a table of the NLEVELS counts that FREQ does.&amp;nbsp; That output can be from a FREQ run-through that selects ODS table NLEVELS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
  input tier1 $ tier2 $ impact;
datalines;
P A 10.25 
P A 10.75
P A 11.33
P A 13.11
P B  9.80
P B 10.33
P B 11.90
P B 12.15
P B 13.42
P C  0.00
P D 10.55
P . 11.11
run;&lt;/PRE&gt;
&lt;P&gt;Proc FREQ with uncontrollable formatting of frequency values&lt;/P&gt;
&lt;PRE&gt;  title "Freq, weighted by IMPACT";
  tables 
    tier1 * tier2       /* two-way crosstabulation, tier1 down the table, tier2 across the table */
  / crosslist           /* arrange output so across values (tier2) appear as an adjacent down list */
    nocum               /* suppress cumulative counts from output, only applies to ONE WAY tables though */
    nocol               /* suppress column percent from ouput */
    norow               /* suppress row percent from ouput */
    
    format=comma12.     /* format for tier2 frequency values, is NOT applied in crosslist mode -- come on SAS, fix that */
    sparse              /* only applied if LIST or OUT= also in effect */
    missprint           /* deal with missing table var values, either:       */
                        /* - as bin value when proc option MISSING in effect */
                        /* - as a summary line below table (default)         */
  ;
  weight impact / zeros;

run;&lt;/PRE&gt;
&lt;P&gt;OUTPUT from FREQ with unwanted decimals in weighted frequency&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="freq A.png" style="width: 317px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40193i32BDA07F969A58D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="freq A.png" alt="freq A.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT NLEVELS and Pre-process data with TABULATE controlling formatting&lt;/P&gt;
&lt;PRE&gt;proc sql; 
  create table have2 as
  select *, 1 as unity, sum(impact) as weighted_freq from have
  group by tier1, tier2
  order by weighted_freq desc;
quit;

ods escapechar = '^';

ods select NLevels;
ods noproctitle;

proc freq data=have nlevels ;
  title "Freq, just NLEVELS";
  tables tier1 * tier2;
run;

proc tabulate data=have2;
  title "TABULATE, UNITY weighted by IMPACT";
  class tier1 tier2 / order=data;
  weight impact;
  var unity;

  table   
    tier1 * tier2 ALL
  ,
    (
      n="Unweighted^{newline}Freq"
      unity * 
        ( sum='Weighted^{newline}Freq' 
          sum='Weighted^{newline}Freq^{newline}(comma12.)' * f=comma12.
          colpctsum='%'
          colpctsum='% (4.)'*f=4.
        )
    ) * [style=[textalign=center]]
  /
    nocellmerge
  ;
run;&lt;/PRE&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="freq B.png" style="width: 371px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40194i1D458579AA97B5A3/image-size/large?v=v2&amp;amp;px=999" role="button" title="freq B.png" alt="freq B.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 16:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-of-Proc-Freq-output/m-p/652101#M195734</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-31T16:47:04Z</dc:date>
    </item>
  </channel>
</rss>

