<?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: Matching variables in 2 datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267495#M52876</link>
    <description>&lt;P&gt;Please provide sample input and expected output data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you can either do a data step merge, sql join, or a format to add the information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 01 May 2016 16:51:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-05-01T16:51:10Z</dc:date>
    <item>
      <title>Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267494#M52875</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Got couple of queries here.&lt;/P&gt;&lt;P&gt;I have 2 datasets - A, B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variable1 in dataset B has e.g name of students.&lt;/P&gt;&lt;P&gt;THe variable (only 1 column) in dataset A had e.g name of students and their place of birth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am confused as to whether merge / join the 2? If I merge, can I rename the variable(in question) in B to match the one in A?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q1) &amp;nbsp;What I need is a dataset that would have all the info as it is in B but the variable1 should also have the name of places of birth of the students wherever it matches.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2) 2 extra columns need to be added to the new dataset - that shows total score of previous year's. and avg total score.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;say,&lt;/P&gt;&lt;PRE&gt;data have;
   input name $ totalscore year;
   datalines;
John 241 2011
Mary 460 2015&lt;/PRE&gt;&lt;P&gt;How do I create the total score of the previous year's for that name?&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 14:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267494#M52875</guid>
      <dc:creator>Antaralib</dc:creator>
      <dc:date>2016-05-01T14:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267495#M52876</link>
      <description>&lt;P&gt;Please provide sample input and expected output data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you can either do a data step merge, sql join, or a format to add the information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 16:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267495#M52876</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-01T16:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267497#M52877</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;thanks..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset A: (this was formed by concatenating 2 (name &amp;amp; country) &amp;nbsp;variables from a previous dataset and all other columns were dropped)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Namecountry&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset B:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rank# &amp;nbsp;name &amp;nbsp;score avg score&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output: &amp;nbsp;The country from A should be joined to B(name variable). Wherever there is a match.&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 16:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267497#M52877</guid>
      <dc:creator>Antaralib</dc:creator>
      <dc:date>2016-05-01T16:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267498#M52878</link>
      <description>&lt;P&gt;Note: The labels are different in A &amp;amp; B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Renaming the KEY label does not work.&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 17:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267498#M52878</guid>
      <dc:creator>Antaralib</dc:creator>
      <dc:date>2016-05-01T17:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267500#M52879</link>
      <description>&lt;P&gt;What doesn't work? Please post what you've tried.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That isn't really sample data, please include some observations, fake if necessary, that can be used to replicate your issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 17:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267500#M52879</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-01T17:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267502#M52881</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879" target="_blank"&gt;@Reeza&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;suggested provide sample data sets that clearly describe information contained for a proper solution. Based on information provided seems like you are looking for something like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data A; &lt;BR /&gt;input Namecountry $20.;&lt;BR /&gt;datalines;&lt;BR /&gt;abcCanada&lt;BR /&gt;defUS&lt;BR /&gt;ghqCanada&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data B;&lt;BR /&gt;input Rank name $ score avg_score;&lt;BR /&gt;datalines;&lt;BR /&gt;1 abc 23 20&lt;BR /&gt;2 def 21 23&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select b.*,substr(Namecountry,length(name)+1) as Country from B&lt;BR /&gt;left join A on&lt;BR /&gt;substr(Namecountry,1,length(name))=name;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2016 17:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267502#M52881</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-05-01T17:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267522#M52885</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42042"&gt;@stat_sas﻿&lt;/a&gt;&lt;/P&gt;&lt;P&gt;absolutely those are the input lines.&lt;/P&gt;&lt;P&gt;Could you please tell what's the 'b' in your procsql I assume it's my dataset table B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 01:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267522#M52885</guid>
      <dc:creator>Antaralib</dc:creator>
      <dc:date>2016-05-02T01:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267523#M52886</link>
      <description>&lt;P&gt;But, is there a SAS code to resolve it and not having used procsql.&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 01:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267523#M52886</guid>
      <dc:creator>Antaralib</dc:creator>
      <dc:date>2016-05-02T01:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267526#M52887</link>
      <description>&lt;P&gt;It depends. Do you have duplicates in any of your tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise use a MERGE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, much easier if you post sample data and output to illustrate your issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc SQL is very powerful for joining and merging datasets, it's worth learning the basics.&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 02:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267526#M52887</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-02T02:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Matching variables in 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267535#M52889</link>
      <description>&lt;P&gt;Yes, A and B are table names&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 05:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-variables-in-2-datasets/m-p/267535#M52889</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-05-02T05:26:19Z</dc:date>
    </item>
  </channel>
</rss>

