<?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: Returning a result of '0' for a combination of variables where no instances of the combination e in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533304#M146205</link>
    <description>&lt;P&gt;Thanks for the useful thread&lt;/P&gt;&lt;P&gt;A&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Feb 2019 15:43:53 GMT</pubDate>
    <dc:creator>AJChamberlain</dc:creator>
    <dc:date>2019-02-06T15:43:53Z</dc:date>
    <item>
      <title>Returning a result of '0' for a combination of variables where no instances of the combination exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533188#M146154</link>
      <description>&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in SAS with variables Var1 Var2 and Var3, Var1 is A or B Var2 is X or Y and for each combination of these I count the number of instances of Var 3. So this dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;TD&gt;Var3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt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;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but when there are no instances of some combinations I still want to report a null result as zero for all combinations, so for example this dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;TD&gt;Var3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;produces this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where I want it to produce this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using proc SQL to count my instances, but I need some way of telling the system to look out for all combinations of Var1 and Var2 and return 0 where they don't exist. Can anyone tell me how I might do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas gratefully received!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 11:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533188#M146154</guid>
      <dc:creator>AJChamberlain</dc:creator>
      <dc:date>2019-02-06T11:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a result of '0' for a combination of variables where no instances of the combination e</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533191#M146156</link>
      <description>&lt;P&gt;Is your data representable of your actual problem? I.e, do you only have the two categories A and B to worry about, or do you have more?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the approaches in this thread may be of help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/td-p/325505" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/td-p/325505&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 11:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533191#M146156</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-06T11:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a result of '0' for a combination of variables where no instances of the combination e</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533303#M146204</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250288"&gt;@AJChamberlain&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when there are no instances of some combinations I still want to report a null result as zero for all combinations, so for example this dataset:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you looking for a dataset (used by other parts of a program0 or a report (people read these)?&lt;/P&gt;
&lt;P&gt;Do you &lt;STRONG&gt;know&lt;/STRONG&gt; all the values that Var1 and Var2 will have? Then perhaps a format for the var1 and the option Preloadfmt&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $v
'A'='A'
'B'='B'
;
run;
data have;
input Var1 $ Var2 $ Var3 ;
datalines;
A X 1 
A Y 1 
A X 1 
A X 1 
A X 1 
A X 1 
A Y 1 
A Y 1 
;
run;

proc tabulate data=have;
   class var1 /preloadfmt;
   format var1 $v.;
   class var2;
   var var3;
   table var1,
         var2*var3=''*n=''
         /printmiss
   ;
run;
   &lt;/PRE&gt;
&lt;P&gt;Proc means/summary will do similar for a data set though you need to add options&lt;U&gt;&amp;nbsp;completetypes&lt;/U&gt; and missing to the proc statement.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 15:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533303#M146204</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-06T15:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a result of '0' for a combination of variables where no instances of the combination e</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533304#M146205</link>
      <description>&lt;P&gt;Thanks for the useful thread&lt;/P&gt;&lt;P&gt;A&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 15:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-result-of-0-for-a-combination-of-variables-where-no/m-p/533304#M146205</guid>
      <dc:creator>AJChamberlain</dc:creator>
      <dc:date>2019-02-06T15:43:53Z</dc:date>
    </item>
  </channel>
</rss>

