<?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 Re: PROC FREQ - Include Zero Counts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325807#M62275</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What appears to be happening in the PROC SUMMARY, before I added the WAYS 1 parameter at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;'s suggestion, was that, in the output data set, each variable's format categories were repeated for each category of each format for the preceeding variable which were in turn repeated for each category of the variable preceeding that, and so on, winding up with something that looks suspiciously like a Cartesian product. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With just 5 variables with 20ish format categories each, I wound up with more than 11,000,000 combinations. &amp;nbsp;It's hardly a wonder that it wouldn't work with 145 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6787iC126320959F44A52/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Screen_Print_of_Cartesian_Product_of_Formats.jpg" title="Screen_Print_of_Cartesian_Product_of_Formats.jpg" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jan 2017 20:54:22 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2017-01-18T20:54:22Z</dc:date>
    <item>
      <title>PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325505#M62255</link>
      <description>&lt;P&gt;I have a set of 145 numeric variables whose counts I want to compare period to period. &amp;nbsp;For example, I might want to compare January of this year&amp;nbsp;to January of last year or January of this year to, say, April of last year. &amp;nbsp;Easy enough to get the counts using "one way" tables in PROC FREQ, but when displayed side by side, the rows don't necessarily line up. &amp;nbsp;If a particular period doesn't have any instances in a given range, then PROC FREQ will omit that range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
    VALUE TV_MON_20YM 
	0 = '0 months'
	1-2 = '1 to 2 months'
	3-4 = '3 to 4 months'
	5-6 = '5 to 6 months'
	7-8 = '7 to 8 months'
	9-10 = '9 to 10 months'
	11-12 = '11 to 12 months'
	13 - 99999 = '&amp;gt; 12 months'
	;

RUN;

PROC	FREQ	DATA=Comp_Lib.&amp;amp;Comp_File;
	TABLES	TV_PS_PSA008	/	MISSING;
	FORMAT	TV_PS_PSA008	TV_MON_20YM.;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The most common problem we experience is that there will be no instances of '0 months' for one of the periods being compared. The rows then don't line up period to period. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way that I can have SAS print a '0 months' row even when there are no occurences that have a value of zero? &amp;nbsp;The SPARSE option in PROC FREQ appears to be geared toward two way tables. &amp;nbsp;The PRELOADFMT option appears to also be geared toward two way tables. &amp;nbsp;I just have simple one-way tables. &amp;nbsp;If someonr could point me in the right direction, that would be most helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 22:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325505#M62255</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-17T22:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325510#M62256</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;The SPARSE option in PROC FREQ appears to be geared toward two way tables. &amp;nbsp;The PRELOADFMT option appears to also be geared toward two way tables. &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PRELOADFMT would definitely solve your issue, SPARSE may not helpful. Given your description of comparing things over time and periods, I'm not sure how you have a one way table. You need to post some more sample data that reflects your problem, this isn't enough to illustrate it beyond the standard use a PRELOADFMT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 23:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325510#M62256</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-17T23:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325513#M62257</link>
      <description>&lt;P&gt;This is how I would do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
   VALUE TV_MON_20YM(notsorted)
      0 = '0 months'
      1-2 = '1 to 2 months'
      3-4 = '3 to 4 months'
      5-6 = '5 to 6 months'
      7-8 = '7 to 8 months'
      9-10 = '9 to 10 months'
      11-12 = '11 to 12 months'
      13 - 99999 = '&amp;gt; 12 months'
   ;
   RUN;
data compfile;
   TV_PS_PSA008=3;
   run;
proc summary data=compfile nway completetypes;
   class TV_PS_PSA008 / preloadfmt order=data missing;
   FORMAT	TV_PS_PSA008	TV_MON_20YM.;
   output out=counts;
   run;
proc print;
   run;
PROC	FREQ	DATA=counts order=data;
   TABLES	TV_PS_PSA008	/	MISSING;
   weight _freq_ / zeros;
   FORMAT	TV_PS_PSA008	TV_MON_20YM.;
   RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/6773i5B26B8386E3463DF/image-size/original?v=v2&amp;amp;px=-1" border="0" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 23:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325513#M62257</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-17T23:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325543#M62258</link>
      <description>&lt;P&gt;OK,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;, that works. That gives me the results I need including the zero counts. &amp;nbsp;It runs pretty fast with a couple of variables, but really really slow with more. &amp;nbsp;I may have done something wrong there; not sure. If the slowness I'm noticing is just part and parcel of having 145 variables and about 800,000 - 1,000,000 records, then I can turn it into a macro or something and just put through a few variables at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 02:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325543#M62258</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-18T02:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325544#M62259</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, I'm just producing two sets of one-way frequency counts, one for the current period, one for a prior period. &amp;nbsp;The one-way counts are then laid side-by-side for presentation purposes and Excel macros highlight any differences.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;proposed is working, albeit slowly, so I won't post more detail at this juncture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your input,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 02:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325544#M62259</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-18T02:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325547#M62260</link>
      <description>&lt;P&gt;The slowness is probably from generating the results, try turning on the NOPRINT option or the listing output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 02:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325547#M62260</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-18T02:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325550#M62261</link>
      <description>Ways 1;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 18 Jan 2017 02:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325550#M62261</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-18T02:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325562#M62262</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt; wrote:&lt;BR /&gt;Ways 1;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry, you lost me&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 05:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325562#M62262</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-18T05:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325563#M62263</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, &amp;nbsp;Ah. &amp;nbsp;Good idea. &amp;nbsp;I will try that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 05:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325563#M62263</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-18T05:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325659#M62266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt; wrote:&lt;BR /&gt;Ways 1;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry, you lost me&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;OK &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;WAYS 1 is what you need to get PROC SUMMARY to just do the 1-way tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1affq2dctdc8un1eokb50s12qbg.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1affq2dctdc8un1eokb50s12qbg.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example program that will handle up to 32767 class variables.&amp;nbsp; The class variables can be either char or numeric as the MLF CLASS statement option converts all class variables to character so they can be arrayed.&amp;nbsp;Then a second data step to normalize the class variables into&amp;nbsp;_NAME_ and _VALUE_ and the class variables are dropped.&amp;nbsp; This is a more manageable data in my opinion.&amp;nbsp; This output can be passed to PROC FREQ with a BY statement if you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
   VALUE TV_MON_20YM(notsorted)
      0 = '0 months'
      1-2 = '1 to 2 months'
      3-4 = '3 to 4 months'
      5-6 = '5 to 6 months'
      7-8 = '7 to 8 months'
      9-10 = '9 to 10 months'
      11-12 = '11 to 12 months'
      13 - 99999 = '&amp;gt; 12 months'
   ;
   RUN;
data compfile;
   do TV_PS_PSA008=3,.;
      TV_PS_PSA006=TV_PS_PSA008;
      TV_PS_PSA010=TV_PS_PSA008;
      output;
      end;
   run;
proc summary data=compfile completetypes chartype;
   class TV_PS_PSA: / preloadfmt order=data missing mlf;
   FORMAT TV_PS_PSA:	TV_MON_20YM.;
   ways 1;
   output out=counts;
   run;
data counts;
   length _order_ 8 _name_ $32 _value_ $64;
   set counts;
   array tv[*] TV_PS_PSA:;
   drop tv:;
   _I_ = indexc(_type_,'1');
   _order_ = length(_type_)-_i_;
   _name_  = vname(tv[_i_]);
   _value_ = tv[_i_];
   run;
proc print;
   run;
proc freq data=counts order=data;
   by _order_ _name_;
   tables _value_;
   weight _freq_ / zeros;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/6775iD585C4AD7C91FADA/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 12:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325659#M62266</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-18T12:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FREQ - Include Zero Counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325807#M62275</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What appears to be happening in the PROC SUMMARY, before I added the WAYS 1 parameter at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;'s suggestion, was that, in the output data set, each variable's format categories were repeated for each category of each format for the preceeding variable which were in turn repeated for each category of the variable preceeding that, and so on, winding up with something that looks suspiciously like a Cartesian product. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With just 5 variables with 20ish format categories each, I wound up with more than 11,000,000 combinations. &amp;nbsp;It's hardly a wonder that it wouldn't work with 145 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6787iC126320959F44A52/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Screen_Print_of_Cartesian_Product_of_Formats.jpg" title="Screen_Print_of_Cartesian_Product_of_Formats.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 20:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/m-p/325807#M62275</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2017-01-18T20:54:22Z</dc:date>
    </item>
  </channel>
</rss>

