<?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: Add information to an existing dataset in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294944#M61582</link>
    <description>Thanks for the code. I believe the "WANT" data is the data holding the continent. is that correct?&lt;BR /&gt;</description>
    <pubDate>Mon, 29 Aug 2016 20:33:41 GMT</pubDate>
    <dc:creator>tafteh</dc:creator>
    <dc:date>2016-08-29T20:33:41Z</dc:date>
    <item>
      <title>Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294934#M61577</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have a dataset in SAS which includes person_id, and the country. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Person_id, Country&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 USA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 USA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3, GER&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4, DEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I add the continent info to its current data set? can I do it using macro? so the resulting data set be like the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Person_id, Country, Continent&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 USA NORTH AMERICA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 USA&amp;nbsp;&lt;SPAN&gt;NORTH AMERICA&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3, GER&amp;nbsp;&lt;SPAN&gt;Europe&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4, DEN&amp;nbsp;&lt;SPAN&gt;Europe&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294934#M61577</guid>
      <dc:creator>tafteh</dc:creator>
      <dc:date>2016-08-29T20:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294938#M61578</link>
      <description>&lt;P&gt;Do you have that content information in a data set? Especially if it has the contry name/abbreviation, then an SQL join would possibly be the easiest. If not, then building such a set may be the first thing to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294938#M61578</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-29T20:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294941#M61580</link>
      <description>&lt;P&gt;you don't need a macro to do it;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can add:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; select&amp;nbsp;(country) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('USA') continent = '&lt;SPAN&gt;NORTH AMERICA&lt;/SPAN&gt;';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('GER' 'DEN') continent = 'EUROPE';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; otherwize continent = 'OTHER';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or you can do it by creating a format &amp;nbsp;to get the continent of the country:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; proc format lib=worl;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value $continent&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'USA' = '&lt;SPAN&gt; NORTH AMERICA'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'GER' = 'EUROPE'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'DEN' = 'EUROPE'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;otehr = 'Not Defined'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; data WANT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set HAVE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;length continent $25;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continent = putc(country, $continent.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294941#M61580</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-08-29T20:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294942#M61581</link>
      <description>&lt;P&gt;Thanks for your anaswer &lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_self"&gt;ballardw&lt;/A&gt;,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;is there anychance I could have sample SAS code of the solution? I think one approach is to create a reference table/data set to hold countries and the continent. Then using the a macro, each row of the current data_set (person_ID and country) being fed to and withing the macro, the continent info is fetched, and fanially being added to the current data set as the new column/variable. Can you help me with the sample code of the above solution?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294942#M61581</guid>
      <dc:creator>tafteh</dc:creator>
      <dc:date>2016-08-29T20:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294944#M61582</link>
      <description>Thanks for the code. I believe the "WANT" data is the data holding the continent. is that correct?&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/294944#M61582</guid>
      <dc:creator>tafteh</dc:creator>
      <dc:date>2016-08-29T20:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/295008#M61599</link>
      <description>&lt;P&gt;That's right - WANT is rhe output dataset with the new variable CONTINENT;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 23:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/295008#M61599</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-08-29T23:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add information to an existing dataset in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/295016#M61600</link>
      <description>&lt;P&gt;This is not a problem where macro code would be very useful. &amp;nbsp;You do not need to dynamically generate SAS code. &amp;nbsp;You just need to use normal SAS statements to manipulate your data. First let's make dataset out of your example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input person_id country $ ;
cards;
1 USA
2 USA
3 GER
4 DEN
;

data country2continent ;
  input country $ continent $20. ;
cards;
USA NORTH AMERICA
GER EUROPE
DEN EUROPE
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Then we can combine them. For example by using an SQL join.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  create table want as 
   select a.*,b.continent
   from have a 
   left join country2continent b
   on a.country = b.country
 ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 00:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-information-to-an-existing-dataset-in-SAS/m-p/295016#M61600</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-30T00:22:15Z</dc:date>
    </item>
  </channel>
</rss>

