<?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: if creates variables that are missing from the data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371990#M88898</link>
    <description>&lt;P&gt;Since you're likely in a macro already why not use macro variables here? Your pattern has a logic so it would make sense here.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 05:24:33 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-06-30T05:24:33Z</dc:date>
    <item>
      <title>if creates variables that are missing from the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371984#M88896</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a program that inlcudes a loop&amp;nbsp;that reads different data sets and then do different operations depening on the data set.&lt;/P&gt;&lt;P&gt;for example, say i have data A (with variables ID, A1 and A2) and data B (with variables ID, B1 and B2). and the ID variable has either A or B, depending on which data set it is.&lt;/P&gt;&lt;P&gt;I have a loop in which i read the data set and then does (this is a simplification of the code, just to illustrate):&lt;/P&gt;&lt;P&gt;if &amp;nbsp;ID='A' and&amp;nbsp;&amp;nbsp;A1=A2 then C=3;&lt;/P&gt;&lt;P&gt;if ID='B' &lt;SPAN&gt;and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;B1&lt;/SPAN&gt;&lt;SPAN&gt;=B&lt;/SPAN&gt;&lt;SPAN&gt;2 then C=2&lt;/SPAN&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that when data A is read, SAS creats variables B1 and B2, and when data B is read, it creates varaible A1 and A2. How can I avoid that?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 04:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371984#M88896</guid>
      <dc:creator>Tzur</dc:creator>
      <dc:date>2017-06-30T04:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: if creates variables that are missing from the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371990#M88898</link>
      <description>&lt;P&gt;Since you're likely in a macro already why not use macro variables here? Your pattern has a logic so it would make sense here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 05:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371990#M88898</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-30T05:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: if creates variables that are missing from the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371992#M88899</link>
      <description>&lt;P&gt;I am actually trying this now and it seems to work, but I would still like to understnad why SAS behave in this way. Basically, why does it creates variables that are not in the data set?&lt;/P&gt;&lt;P&gt;In this case, it creates varaibles B1 and B2 eventhough the first part of the if condition is not met (ID does not equal B). I thought that in that case, SAS would just ignore the rest of the statement, but instead, it creates these variables. I'd like to know why it does that and if there is a way around it?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 05:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/371992#M88899</guid>
      <dc:creator>Tzur</dc:creator>
      <dc:date>2017-06-30T05:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: if creates variables that are missing from the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/372000#M88900</link>
      <description>&lt;P&gt;One of the drawbacks of a language that doesn't require you to declare variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It assumes the variable exists and that you'll use it accordingly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As as far as I know there isn't a way to change the default behaviour. You could try and get around it with by using VVALUEX instead&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If vvaluex(id||'1')=vvaluex(id||'2') then do;
     If id='A' then C=2;
     If id='B' then C=3;
End;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 05:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-creates-variables-that-are-missing-from-the-data/m-p/372000#M88900</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-30T05:46:42Z</dc:date>
    </item>
  </channel>
</rss>

