<?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: Assessing column in table during DATA step merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496324#M131232</link>
    <description>if foo = 'a' then myvar = 1; works</description>
    <pubDate>Mon, 17 Sep 2018 17:23:27 GMT</pubDate>
    <dc:creator>tomrvincent</dc:creator>
    <dc:date>2018-09-17T17:23:27Z</dc:date>
    <item>
      <title>Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496318#M131227</link>
      <description>&lt;P&gt;Let's say I have two tables that are being merged and I need to access the value of a column in one to determine the value of a new column in the resulting join.&amp;nbsp; For instance:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
  input foo $;
  datalines;
a
b
c
d
;
run;

data bar;
  input foo $;
  datalines;
a
b
c
d
;
run;

data merged;
  merge foo(in=a) bar(in=b);
  by foo;
  if a.foo = 'a' then myvar = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm getting this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 557-185: Variable a is not an object.&lt;/PRE&gt;&lt;P&gt;How can I check the value of table foo column a within the DATA step?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496318#M131227</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-09-17T17:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496324#M131232</link>
      <description>if foo = 'a' then myvar = 1; works</description>
      <pubDate>Mon, 17 Sep 2018 17:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496324#M131232</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-09-17T17:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496325#M131233</link>
      <description>&lt;P&gt;When variables are merged with the same name, the one on the right overwrites the first one, so you need to rename them so they're different variables and then do a comparison.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you may be able to get what you want here with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and foo='a' then ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496325#M131233</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T17:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496326#M131234</link>
      <description>&lt;P&gt;IN= is a dataset option that will give Boolean values (Always 0 or 1). It is not an alias name for the dataset like in sql alias reference.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Creates a Boolean variable that indicates whether the data set contributed data to the current observation.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/viewer.htm#n1p1o2dsuc465nn198ovwdrj9mvy.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/viewer.htm#n1p1o2dsuc465nn198ovwdrj9mvy.htm&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496326#M131234</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-17T17:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496327#M131235</link>
      <description>&lt;P&gt;What if the table and the variable have the same name?&amp;nbsp; Let's say there's a table a and a column a in that table.&amp;nbsp; Can you do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and a = 0 then myvar = 1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496327#M131235</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-09-17T17:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496328#M131236</link>
      <description>&lt;P&gt;That would be silly programming to set the IN= variable to one that already exists....not that people don't do that I suppose. I would consider that user error. I get wanting to understand the theory though.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142145"&gt;@tomcmacdonald&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What if the table and the variable have the same name?&amp;nbsp; Let's say there's a table a and a column a in that table.&amp;nbsp; Can you do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and a = 0 then myvar = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496328#M131236</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T17:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496329#M131237</link>
      <description>&lt;P&gt;I'm just thinking from a SQL perspective where you can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when a.a = 0 then 1
end as myvar&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496329#M131237</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-09-17T17:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496334#M131242</link>
      <description>&lt;P&gt;In a data step you don't reference the table name though. You can find a record using the IN but the individual access to the different variables with the same names&amp;nbsp;isn't easily possible. You can probably access it somehow, but that's beyond my skills. Most like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;, or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;may know the answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496334#M131242</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-17T17:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Assessing column in table during DATA step merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496448#M131308</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142145"&gt;@tomcmacdonald&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm just thinking from a SQL perspective where you can do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when a.a = 0 then 1
end as myvar&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Doesn't really make much sense.&lt;/P&gt;
&lt;P&gt;There is just one set of variables in a data step. No matter how many inputs you are reading or output you are writing.&lt;/P&gt;
&lt;P&gt;If you need to reference both variables then one will need to have its name changed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; merge a(rename=(a=a_from_a)) b;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 03:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assessing-column-in-table-during-DATA-step-merge/m-p/496448#M131308</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-18T03:25:05Z</dc:date>
    </item>
  </channel>
</rss>

