<?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: Use data from another table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/271940#M18857</link>
    <description>&lt;P&gt;There are several methods you an use to do this - merging the two datasets, SQL join, SQL lookup, hash table. &amp;nbsp;You have not posted any test data (in the form of datasteps) or what the output should be so can't provide acurate code. &amp;nbsp;Generally speaking its not a good idea to reference a data element (observation) by position in the dataset as this can change drastically on each run. &amp;nbsp;Assigning an order to the data, even if it just takes the automatic variable _n_ is better than nothing:&lt;/P&gt;
&lt;PRE&gt;data output;
  merge input1 
             input1 (where=(ord=1) keep=v1 rename=variable1=v1)
             input1 (where=(ord=2) keep=v2 rename=variable1=v2)
...
  by &amp;lt;id_vars&amp;gt;;
run;&lt;/PRE&gt;
&lt;P&gt;Or lookup:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table OUTPUT as
  select  VARIABLE1,
             (select VARIABLE1 from HAVE where ORD=1) as VAR1,
             (select VARIABLE1 from HAVE where ORD=2) as VAR2,
...
             case when VARIABLE1 le CALCULATED VAR1 then 0
                      when ...
                      else . end as TIER
  from    HAVE;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2016 10:56:53 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-20T10:56:53Z</dc:date>
    <item>
      <title>Use data from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/271936#M18854</link>
      <description>&lt;P&gt;I have a dataset called INPUT1 on which I want to act. And a dataset called INPUT2 which will serve purely as input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More specifically I want to do the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; OUTPUT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;INPUT1;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;MARK=&amp;lt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;1&lt;/FONT&gt;_Variable1_from_INPUT2&lt;/FONT&gt; &lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Tier=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;&amp;gt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;1&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;=&amp;lt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;2&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Tier=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;&amp;gt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;2&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; MARK=&amp;lt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;3&lt;/FONT&gt;_Variable1_from_INPUT2&lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Tier=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;&amp;gt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;3&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;=&amp;lt;&lt;EM&gt;&lt;FONT color="#00ccff" face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;4&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Tier=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;FONT face="Courier New"&gt;MARK&lt;/FONT&gt;&amp;gt;&lt;FONT color="#00ccff"&gt;&lt;EM&gt;&lt;FONT face="Courier New"&gt;ROW&lt;FONT color="#ff0000"&gt;4&lt;/FONT&gt;_Variable1_from_INPUT2 &lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; Tier=&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;How can I do this? If it matters at all, &lt;EM&gt;Variable1&lt;/EM&gt; is numeric and ordered.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;I'm on SAS ENTERPRISE GUIDE 5.1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Thanks.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 10:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/271936#M18854</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-05-20T10:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Use data from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/271940#M18857</link>
      <description>&lt;P&gt;There are several methods you an use to do this - merging the two datasets, SQL join, SQL lookup, hash table. &amp;nbsp;You have not posted any test data (in the form of datasteps) or what the output should be so can't provide acurate code. &amp;nbsp;Generally speaking its not a good idea to reference a data element (observation) by position in the dataset as this can change drastically on each run. &amp;nbsp;Assigning an order to the data, even if it just takes the automatic variable _n_ is better than nothing:&lt;/P&gt;
&lt;PRE&gt;data output;
  merge input1 
             input1 (where=(ord=1) keep=v1 rename=variable1=v1)
             input1 (where=(ord=2) keep=v2 rename=variable1=v2)
...
  by &amp;lt;id_vars&amp;gt;;
run;&lt;/PRE&gt;
&lt;P&gt;Or lookup:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table OUTPUT as
  select  VARIABLE1,
             (select VARIABLE1 from HAVE where ORD=1) as VAR1,
             (select VARIABLE1 from HAVE where ORD=2) as VAR2,
...
             case when VARIABLE1 le CALCULATED VAR1 then 0
                      when ...
                      else . end as TIER
  from    HAVE;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 10:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/271940#M18857</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T10:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use data from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/272002#M18864</link>
      <description>&lt;P&gt;How can I define ORD to display&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1
2
3
4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Without doing it "manually"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 14:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/272002#M18864</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-05-20T14:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Use data from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/272011#M18867</link>
      <description>&lt;P&gt;OK, got it. It's just&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ORD=_n_&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I didn't know about this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to make&amp;nbsp;your second option&amp;nbsp;work at the moment.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 15:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-data-from-another-table/m-p/272011#M18867</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-05-20T15:29:09Z</dc:date>
    </item>
  </channel>
</rss>

