<?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: Merge value of 1 variable value with another variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121638#M259803</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Haikuo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are right. The Second row critical value should be 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To tell you the truth, I am 100% blank reading your code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will learn.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the mean time, if other members have any other approach, please help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Jun 2013 03:49:02 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2013-06-28T03:49:02Z</dc:date>
    <item>
      <title>Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121636#M259801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 2 files:&lt;/P&gt;&lt;P&gt;File 1: Tracking value of variable (A B C D E…) overtime&lt;/P&gt;&lt;P&gt;Date A B &lt;BR /&gt;1 4 5 &lt;BR /&gt;2 1 5 &lt;BR /&gt;3 2 1 &lt;BR /&gt;4 8 3&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;File 2:&amp;nbsp; have the critical value for each variable&lt;BR /&gt;Name&amp;nbsp; Critical &lt;BR /&gt;A&amp;nbsp; 3&lt;BR /&gt;A&amp;nbsp; 2&lt;BR /&gt;B&amp;nbsp; 3&lt;BR /&gt;B&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;I want to combine 2 files to get the date where a variable is above critical value&lt;/P&gt;&lt;P&gt;Name&amp;nbsp;&amp;nbsp; Critical&amp;nbsp; Date&lt;BR /&gt;A&amp;nbsp; 3&amp;nbsp; 1&lt;BR /&gt;A&amp;nbsp; 3&amp;nbsp; 4&lt;BR /&gt;A&amp;nbsp; 4&amp;nbsp; 4&lt;BR /&gt;B&amp;nbsp; 3&amp;nbsp; 1&lt;BR /&gt;B&amp;nbsp; 3&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;I don’t know how to do that kind of merge and very appreciate if you could help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data time;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input date a b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;1 4 5 &lt;BR /&gt;2 1 5 &lt;BR /&gt;3 2 1 &lt;BR /&gt;4 8 3 &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; data critical;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input name $ critical;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;A&amp;nbsp; 3&lt;BR /&gt;A&amp;nbsp; 2&lt;BR /&gt;B&amp;nbsp; 3&lt;BR /&gt;B&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;;;;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 02:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121636#M259801</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-06-28T02:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121637#M259802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I envision that you maybe able to do it by transposing one of your tables first, then Proc SQL.&amp;nbsp; But here is a Hash approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data time;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input date a b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1 4 5&lt;/P&gt;&lt;P&gt;2 1 5&lt;/P&gt;&lt;P&gt;3 2 1&lt;/P&gt;&lt;P&gt;4 8 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; data critical;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input name $ critical;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;B&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;B&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set critical;&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash h(dataset:'critical', multidata:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definekey('name');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definedata(all:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash want(multidata:'y',ordered:'a');&lt;/P&gt;&lt;P&gt;&amp;nbsp; want.definekey('name','critical');&lt;/P&gt;&lt;P&gt;&amp;nbsp; want.definedata('name','critical','date');&lt;/P&gt;&lt;P&gt;&amp;nbsp; want.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set time end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array ab a b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do over ab;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do rc=h.find(key:upcase(vname(ab))) by 0 while (rc=0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if critical &amp;lt; ab then want.replace();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rc=h.find_next(key:upcase(vname(ab))) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then want.output(dataset:'want');&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, I supposed that you have a typo in 'critical' table, the second row 'critical' value should be '4' instead of '2' per your output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 03:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121637#M259802</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-06-28T03:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121638#M259803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Haikuo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are right. The Second row critical value should be 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To tell you the truth, I am 100% blank reading your code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will learn.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the mean time, if other members have any other approach, please help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 03:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121638#M259803</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-06-28T03:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121639#M259804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does your output match your data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have two critical values for A, how does that work in terms of date?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think a SQL merge would be simple enough, but having a hard time figuring out what your requirements are.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 04:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121639#M259804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-06-28T04:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121640#M259805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is SQL version:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data time;
&amp;nbsp;&amp;nbsp; input date a b;
&amp;nbsp;&amp;nbsp; datalines;
1 4 5
2 1 5
3 2 1
4 8 3
;

&amp;nbsp;&amp;nbsp; data critical;
&amp;nbsp;&amp;nbsp; input name $ critical;
&amp;nbsp;&amp;nbsp; datalines;
A&amp;nbsp; 3
A&amp;nbsp; 4
B&amp;nbsp; 3
B&amp;nbsp; 7
;

proc transpose data=time out=temp ;
by date;
var a b;
run;
proc sql;
 create table want as
&amp;nbsp; select name,critical,date
&amp;nbsp;&amp;nbsp; from critical,temp
&amp;nbsp;&amp;nbsp;&amp;nbsp; where name=upcase(_name_) and col1 gt critical
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by Name,Critical&amp;nbsp; ;
quit;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 05:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121640#M259805</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-06-28T05:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge value of 1 variable value with another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121641#M259806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza&amp;nbsp; and Ksharp,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I face this problem after working on the one Ksharp helped me last time, where I create 2 name variables for the combination.&lt;/P&gt;&lt;P&gt;Actually, on critical file, there are 2 conditions for Variable A and Variable B as below. Therefore I don't think the SQL will help.&lt;/P&gt;&lt;P&gt;(So my effort to simplify this problem misleading this time)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the output in this case should be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;name1 name2 critical1 critical2 date&lt;/P&gt;&lt;P&gt;A B 3 2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;A B 3 2&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;A C 3 12 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data time;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input date a b c;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;1 4 5 2&lt;BR /&gt;2 1 5 8&lt;BR /&gt;3 2 1 9&lt;BR /&gt;4 8 3 50&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; data critical;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input name1 $ name2 $ critical1 critical2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;A B 3 2&lt;BR /&gt;A C 3 12&lt;BR /&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 19:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-value-of-1-variable-value-with-another-variable-name/m-p/121641#M259806</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-06-28T19:44:12Z</dc:date>
    </item>
  </channel>
</rss>

