<?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: Problem with if/then statement, one category isn't showing up in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/784025#M250118</link>
    <description>Thank you! I haven't fully figured out what's going on yet, but this was really helpful in getting me to the next step. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Fri, 03 Dec 2021 22:08:34 GMT</pubDate>
    <dc:creator>joachimg</dc:creator>
    <dc:date>2021-12-03T22:08:34Z</dc:date>
    <item>
      <title>Problem with if/then statement, one category isn't showing up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783481#M249818</link>
      <description>&lt;P&gt;I'm trying to create a variable with 3 levels (0, 1, and 2) just using a simple if/then statement from other binary variables. However, the 0 level is not showing up when I then run a proc freq/tables. I can't seem to figure out what's going wrong. Is the 0 level being overwritten because of how I've coded it? Or something else I'm not seeing? Here's my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data pk06;
set pk06;
if bcg=0 and polio1=0 and polio0=0 and measles=0 and dtp1=0 then fullvax=0;
else if bcg=1 and polio_full=1 and measles=1 and dtp3=1 then fullvax=2;
else fullvax=1;
run;

proc freq data=pk06;
where 1 le b8 le 4;
tables fullvax;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here's a screenshot of the table I'm getting:&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="joachimg_0-1638399005619.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66318i4A701877B5775052/image-size/medium?v=v2&amp;amp;px=400" role="button" title="joachimg_0-1638399005619.png" alt="joachimg_0-1638399005619.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm fairly confident that there should be observations that fall into the 0 level, and I would think that even if there were 0 observations there, I would get a row that had 0 as the frequency. Let me know if you need more information! Thanks so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 22:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783481#M249818</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2021-12-01T22:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with if/then statement, one category isn't showing up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783484#M249819</link>
      <description>&lt;P&gt;Honestly we can't tell. You're using different variables in your conditions, and we don't know your variables or how they relate so there's not an easy way to figure this out. &lt;BR /&gt;&lt;BR /&gt;Try filtering and see if you get any records? If this doesn't return records it means your condition isn't right somehow.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
set pk06;
where bcg=0 and polio1=0 and polio0=0 and measles=0 and dtp1=0 and 1 le b8 le 4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393705"&gt;@joachimg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create a variable with 3 levels (0, 1, and 2) just using a simple if/then statement from other binary variables. However, the 0 level is not showing up when I then run a proc freq/tables. I can't seem to figure out what's going wrong. Is the 0 level being overwritten because of how I've coded it? Or something else I'm not seeing? Here's my code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data pk06;
set pk06;
if bcg=0 and polio1=0 and polio0=0 and measles=0 and dtp1=0 then fullvax=0;
else if bcg=1 and polio_full=1 and measles=1 and dtp3=1 then fullvax=2;
else fullvax=1;
run;

proc freq data=pk06;
where 1 le b8 le 4;
tables fullvax;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here's a screenshot of the table I'm getting:&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="joachimg_0-1638399005619.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66318i4A701877B5775052/image-size/medium?v=v2&amp;amp;px=400" role="button" title="joachimg_0-1638399005619.png" alt="joachimg_0-1638399005619.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm fairly confident that there should be observations that fall into the 0 level, and I would think that even if there were 0 observations there, I would get a row that had 0 as the frequency. Let me know if you need more information! Thanks so much.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 23:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783484#M249819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-01T23:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with if/then statement, one category isn't showing up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783528#M249845</link>
      <description>&lt;P&gt;First warning: Use of the code construct with the input and output data set the same name is a likely problem because you may have left over erroneous values from a previous run. When recoding to create new variables strongly recommend creating a new data set so you can compare before/after results without the possibility of overwriting any of your existing data values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data pk06;
set pk06;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Code to check recoding behavior would look like like: &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=pk06;&lt;/CODE&gt;&lt;BR /&gt;tables &lt;CODE class=""&gt;bcg* polio1* polio0* polio_full measles* dtp1* dpt3* fullvax&lt;/CODE&gt;/ list missing;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;The LIST option makes the values all appear on one row so you can see if the values are recoding correctly for each combination of the variables. The MISSING brings in values that you have not really addressed (appearing in the Else). You do not check results with with a filter like the Where statement unless that is really a requirement when assigning the values. Your where may have removed all the 0 Fullvax values for all we can see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 03:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783528#M249845</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-02T03:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with if/then statement, one category isn't showing up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783532#M249849</link>
      <description>&lt;P&gt;You simply don't have data that matches:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;bcg=0 and polio1=0 and polio0=0 and measles=0 and dtp1=&lt;/CODE&gt;0 and &lt;CODE class=""&gt;1 le b8 le 4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Your test syntax is fine and nothing gets overwritten.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 04:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/783532#M249849</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-12-02T04:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with if/then statement, one category isn't showing up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/784025#M250118</link>
      <description>Thank you! I haven't fully figured out what's going on yet, but this was really helpful in getting me to the next step. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 03 Dec 2021 22:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-if-then-statement-one-category-isn-t-showing-up/m-p/784025#M250118</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2021-12-03T22:08:34Z</dc:date>
    </item>
  </channel>
</rss>

