<?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: Converting Data Using Another Data Set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431350#M281689</link>
    <description>&lt;P&gt;You may also want to be aware that in many parts of the US the first three digits of a&amp;nbsp;Zip code &amp;nbsp;will not determine county.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance in my state we have 44 counties and only 7 different values of first three digits in the Zip, the county counts ranging from 1 to 11 per 3-digit code.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2018 17:14:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-01-26T17:14:45Z</dc:date>
    <item>
      <title>Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431159#M281683</link>
      <description>&lt;P&gt;I am new to SAS and I using SAS 9.4. I am trying to convert data using data from a different data set. The first data set is called data and contains a variable for the first 3 digits of a zip code plus 14 other variables. The second data is called zip and contains the first three digits of a zipcodes along with the corresponding county and city names. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Zip&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;zip_3 (variable name)&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;zip_3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Adjuntas&amp;nbsp; &amp;nbsp; &amp;nbsp; PR&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Aquada&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find some way to merge the data so that the county and state name are in the same observation as the matching zipcodes and if there are any other counties it could be, it is also in the observation. Example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;zip_3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Adjuntas&amp;nbsp; &amp;nbsp; &amp;nbsp; PR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Aquada&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PR&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've tried merging the data, but I have had no luck. I haven't used SAS much outside of merging data with identical variables, so I am at a loss.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 02:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431159#M281683</guid>
      <dc:creator>Bennettr99</dc:creator>
      <dc:date>2018-01-26T02:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431162#M281684</link>
      <description>&lt;P&gt;Your approach of merging is correct, can you explain how it didn't work?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Feel free to include your exact code and error messages.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, the approach I'd recommend would be either a merge (data step or SQL) and/or a format. I'm partial to formats because I find them reusable versus merges and keep a library of formats that I can commonly pull from when needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189323"&gt;@Bennettr99&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am new to SAS and I using SAS 9.4. I am trying to convert data using data from a different data set. The first data set is called data and contains a variable for the first 3 digits of a zip code plus 14 other variables. The second data is called zip and contains the first three digits of a zipcodes along with the corresponding county and city names. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Zip&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;zip_3 (variable name)&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;zip_3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Adjuntas&amp;nbsp; &amp;nbsp; &amp;nbsp; PR&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Aquada&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find some way to merge the data so that the county and state name are in the same observation as the matching zipcodes and if there are any other counties it could be, it is also in the observation. Example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;zip_3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Holtsville&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Adjuntas&amp;nbsp; &amp;nbsp; &amp;nbsp; PR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Aquada&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PR&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've tried merging the data, but I have had no luck. I haven't used SAS much outside of merging data with identical variables, so I am at a loss.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 03:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431162#M281684</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-26T03:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431163#M281685</link>
      <description>And a small FYI, though not helpful if you only have the 3 digit zip, SAS has a bunch of functions that convert ZIP codes to state names and such. &lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1en5dzvubdabmn1czrqdcq9ozv3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1en5dzvubdabmn1czrqdcq9ozv3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Fri, 26 Jan 2018 03:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431163#M281685</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-26T03:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431175#M281686</link>
      <description>&lt;P&gt;I just realized I made a mistake with the merging and I should have been more specific about my problem. This was the code I was using.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA home.merge;
MERGE home.data home.zip;
BY zip_3;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the result (with some variables dropped):&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/18115i580AD5038CDFA0CD/image-size/large?v=1.0&amp;amp;px=-1" border="0" width="350" height="600" title="datasample.PNG" alt="datasample.PNG" /&gt;&lt;/P&gt;&lt;P&gt;The loan_id is from home.data. I need to merge the data without duplicating the data from home.data like it does in this data. I need to find a way to have one ID correspond to multiple Counties or States if the 3 digits of the zip code correspond to multiple zip codes. I also need to remove any observation that does not include data from home.data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if the zip_3 in home.data is 025, all of the five digit zip codes and county names would be listed in the same observation.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 04:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431175#M281686</guid>
      <dc:creator>Bennettr99</dc:creator>
      <dc:date>2018-01-26T04:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431180#M281687</link>
      <description>&lt;P&gt;There are two problems. First you are trying to do a many to many merge.&amp;nbsp; There can be more than one loan per ZIP3 and there are more than one "lookup" value per ZIP3.&amp;nbsp; The second problem is you want transpose you many rows of detailed zipcode into a single observation. If you solve the second one first then the first one disappears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First convert your ZIP dataset to have one observation per ZIP3 value.&amp;nbsp; For example using PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=zip out=zip_name prefix=name ;
  by zip_3 ;
  var name ;
run;
proc tranpose data=zip out=zip_code prefix=zipcode ;
  by zip_3;
  var zipcode ;
run;
data zip_single;
  merge zip_name zip_code ;
  by zip_3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can merge this with your loan data and you will be doing a many to one merge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
   merge loan_data (in=in1) zip_single ;
   by zip_3;
   if in1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 04:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431180#M281687</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-26T04:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431184#M281688</link>
      <description>&lt;P&gt;This works! Thanks for the help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 05:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431184#M281688</guid>
      <dc:creator>Bennettr99</dc:creator>
      <dc:date>2018-01-26T05:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Data Using Another Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431350#M281689</link>
      <description>&lt;P&gt;You may also want to be aware that in many parts of the US the first three digits of a&amp;nbsp;Zip code &amp;nbsp;will not determine county.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance in my state we have 44 counties and only 7 different values of first three digits in the Zip, the county counts ranging from 1 to 11 per 3-digit code.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 17:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Data-Using-Another-Data-Set/m-p/431350#M281689</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-26T17:14:45Z</dc:date>
    </item>
  </channel>
</rss>

