<?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: Creating a new variable using two dataset with different var names and observations in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636572#M19064</link>
    <description>Thank you so much Ksharp!&lt;BR /&gt;It works like a charm.&lt;BR /&gt;What if I want the same thing apples for variable F for every B that equals to again C?&lt;BR /&gt;data one;&lt;BR /&gt;input A B;&lt;BR /&gt;cards;&lt;BR /&gt;4 6&lt;BR /&gt;3 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input C D;&lt;BR /&gt;cards;&lt;BR /&gt;1 3&lt;BR /&gt;2 5&lt;BR /&gt;3 8&lt;BR /&gt;4 7&lt;BR /&gt;5 9&lt;BR /&gt;6 10&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Let say I want to create a table like this:&lt;BR /&gt;A B C D E F&lt;BR /&gt;4 6 . . 7 10&lt;BR /&gt;3 2 . . 8 5&lt;BR /&gt;. . 1 3 . .&lt;BR /&gt;. . 2 5 . .&lt;BR /&gt;. . 3 8 . .&lt;BR /&gt;. . 4 7 . .&lt;BR /&gt;. . 6 10 . .&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 01 Apr 2020 14:22:09 GMT</pubDate>
    <dc:creator>mghamari63</dc:creator>
    <dc:date>2020-04-01T14:22:09Z</dc:date>
    <item>
      <title>Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636533#M19057</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;Assume there are two datasets as follow:&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input A B;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 4 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 3 2&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input C D;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 1 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 2 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 3 8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 4 7&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you see neither variables nor obs are equal.&lt;/P&gt;&lt;P&gt;I would like to create another variable E in dataset one which is equal to var D where A=C. Finally, I am looking for a dataset for example like this:&lt;/P&gt;&lt;P&gt;A B C D E&lt;/P&gt;&lt;P&gt;4 6 . . 7&lt;/P&gt;&lt;P&gt;3 2 . . 8&lt;/P&gt;&lt;P&gt;. .&amp;nbsp; 1 3 .&lt;/P&gt;&lt;P&gt;. .&amp;nbsp; 2 5 .&lt;/P&gt;&lt;P&gt;. .&amp;nbsp; 3 8 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;. . 4 7 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I can do some analyses on A and E.&lt;/P&gt;&lt;P&gt;Please let me know if I can use SAS for this reason.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 13:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636533#M19057</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T13:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636536#M19058</link>
      <description>&lt;P&gt;What if multiple values in C equals A?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 13:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636536#M19058</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-01T13:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636537#M19059</link>
      <description>Thanks!&lt;BR /&gt;&lt;BR /&gt;Yes.&lt;BR /&gt;There are multiple equal values.&lt;BR /&gt;That's another problem I have.</description>
      <pubDate>Wed, 01 Apr 2020 13:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636537#M19059</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T13:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636541#M19060</link>
      <description>&lt;P&gt;What is the logic then?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 13:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636541#M19060</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-01T13:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636548#M19061</link>
      <description>Well, I want to create E according to D for every A that equals to C&lt;BR /&gt;I know it does not work but something like this:&lt;BR /&gt;if A=C then E=D;</description>
      <pubDate>Wed, 01 Apr 2020 13:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636548#M19061</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T13:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636549#M19062</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   input A B;
   cards;
   4 6
   3 2
   ;
run;

data two;
   input C D;
   cards;
   1 3
   2 5
   3 8
   4 7
;
run;

proc sql;
create table want as
select a.*,b.d as e
from (
select * from one
outer union
select * from two) as a
left join two as b on a.a=b.c 
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Apr 2020 13:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636549#M19062</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-04-01T13:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636555#M19063</link>
      <description>&lt;P&gt;This gets exactly what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select one.a, one.b, "" as c, "" as d, two.d as e
from one inner join two
on one.a = two.c
union all corr
select "" as a, "" as b, two.c, two.d, "" as e
from two
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but I am not sure if you actually need this.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 13:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636555#M19063</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T13:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636572#M19064</link>
      <description>Thank you so much Ksharp!&lt;BR /&gt;It works like a charm.&lt;BR /&gt;What if I want the same thing apples for variable F for every B that equals to again C?&lt;BR /&gt;data one;&lt;BR /&gt;input A B;&lt;BR /&gt;cards;&lt;BR /&gt;4 6&lt;BR /&gt;3 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input C D;&lt;BR /&gt;cards;&lt;BR /&gt;1 3&lt;BR /&gt;2 5&lt;BR /&gt;3 8&lt;BR /&gt;4 7&lt;BR /&gt;5 9&lt;BR /&gt;6 10&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Let say I want to create a table like this:&lt;BR /&gt;A B C D E F&lt;BR /&gt;4 6 . . 7 10&lt;BR /&gt;3 2 . . 8 5&lt;BR /&gt;. . 1 3 . .&lt;BR /&gt;. . 2 5 . .&lt;BR /&gt;. . 3 8 . .&lt;BR /&gt;. . 4 7 . .&lt;BR /&gt;. . 6 10 . .&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Apr 2020 14:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636572#M19064</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T14:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636586#M19065</link>
      <description>Thank you KurtBremser!&lt;BR /&gt;&lt;BR /&gt;I'll run it and let you know.&lt;BR /&gt;Cheers!&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Apr 2020 15:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636586#M19065</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T15:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636651#M19066</link>
      <description>Thank you KurtBremser!&lt;BR /&gt;&lt;BR /&gt;This is exactly what I want.&lt;BR /&gt;It will be appreciated if you let me know how to add more variables from dataset one to program. Again the condition is if B=C then F=D;&lt;BR /&gt;&lt;BR /&gt;data one;&lt;BR /&gt;input A B;&lt;BR /&gt;cards;&lt;BR /&gt;4 6&lt;BR /&gt;3 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input C D;&lt;BR /&gt;cards;&lt;BR /&gt;1 3&lt;BR /&gt;2 5&lt;BR /&gt;3 8&lt;BR /&gt;4 7&lt;BR /&gt;5 9&lt;BR /&gt;6 10&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Let say I want to create a table like this:&lt;BR /&gt;A B C D E F&lt;BR /&gt;4 6 . . 7 10&lt;BR /&gt;3 2 . . 8 5&lt;BR /&gt;. . 1 3 . .&lt;BR /&gt;. . 2 5 . .&lt;BR /&gt;. . 3 8 . .&lt;BR /&gt;. . 4 7 . .&lt;BR /&gt;. . 6 10 . .&lt;BR /&gt;&lt;BR /&gt;Thank you for your time.</description>
      <pubDate>Wed, 01 Apr 2020 19:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636651#M19066</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-01T19:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636811#M19067</link>
      <description>&lt;P&gt;So table two is a lookup for values in table one; create a format from it, and use that later:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input A B;
cards;
4 6
3 2
;

data two;
input C D;
cards;
1 3
2 5
3 8
4 7
5 9
6 10
;

data lookup;
set two;
fmtname = "lookup";
type = "i";
rename
  c=start
  d=label
;
run;

proc format cntlin=lookup;
run;

data want;
retain a b c d e f;
call missing(of _all_);
/* these two statements are purely for setting variable order */
set
  one (in=one)
  two
;
if one
then do;
  e = input(put(a,best.),lookup.);
  f = input(put(b,best.),lookup.);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 09:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636811#M19067</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T09:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636833#M19068</link>
      <description>&lt;P&gt;OK. Add one more LEFT JOIN .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   input A B;
   cards;
   4 6
   3 2
   ;
run;

data two;
   input C D;
   cards;
1 3
2 5
3 8
4 7
5 9
6 10
;
run;

proc sql;
create table want as
select a.*,b.d as e,c.d as f
from (
select * from one
outer union
select * from two) as a
left join two as b on a.a=b.c 
left join two as c on a.b=c.c
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 11:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636833#M19068</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-04-02T11:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable using two dataset with different var names and observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636885#M19071</link>
      <description>Thank you so much sir!&lt;BR /&gt;I appreciated your explanations.&lt;BR /&gt;It works correctly.</description>
      <pubDate>Thu, 02 Apr 2020 14:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-a-new-variable-using-two-dataset-with-different-var/m-p/636885#M19071</guid>
      <dc:creator>mghamari63</dc:creator>
      <dc:date>2020-04-02T14:38:09Z</dc:date>
    </item>
  </channel>
</rss>

