<?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: Help using SASHELP.ZIPCODE in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685842#M24333</link>
    <description>&lt;P&gt;If you really just want the last one as it is sorted (or not as in this case) you can use the nosorted option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data lastzip;
  set sashelp.zipcode;
  by state county notsorted;
  if last.county;
run;

&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Sep 2020 19:13:07 GMT</pubDate>
    <dc:creator>CurtisMackWSIPP</dc:creator>
    <dc:date>2020-09-22T19:13:07Z</dc:date>
    <item>
      <title>Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685808#M24326</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to generate a zipcode from the SASHELP.ZIPCODE table that comes with SAS using a county I have in my table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to take the county I have in my table and generate a new variable, called zip_code, that is the last zip code listed for that county (in the SASHELP.ZIPCODE file).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone help with the coding of this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 18:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685808#M24326</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-22T18:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685811#M24327</link>
      <description>&lt;P&gt;show us your data.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 18:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685811#M24327</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-09-22T18:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685817#M24328</link>
      <description>&lt;P&gt;Here is an example of the data:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Denver&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jefferson&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Rifle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want it to look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Zip Code&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Denver&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00010&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jefferson&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Rifle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 00030&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where that zip code is pulled from the SASHELP.ZIPCODE table, and it is the last zip code for the county listed (so for example - zip code 00010 would be the last zip code listed under the Denver County zip codes in the&amp;nbsp;SASHELP.ZIPCODE table)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 18:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685817#M24328</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-22T18:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685835#M24329</link>
      <description>&lt;P&gt;I'm not sure what you mean by the "last" zip, but something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.zipcode out=zips;
  by state county;
run; 

data lastzip;
  set zips;
  by state county;
  if last.county;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685835#M24329</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-22T19:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685837#M24330</link>
      <description>He did, its SASHELP.ZIPCODES</description>
      <pubDate>Tue, 22 Sep 2020 19:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685837#M24330</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-22T19:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685838#M24331</link>
      <description>&lt;P&gt;By last zip code, I mean that for every county in the SASHELP.ZIPCODE table, there are going to be multiple zip codes listed (for example - for Denver county, there might be 10 zip codes from 00000 to 00010) and I want whatever the last zip code for that county to be reflected in the table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think using the last. function is correct I am just not sure exactly how to use it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685838#M24331</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-22T19:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685839#M24332</link>
      <description>&lt;P&gt;Did my example not solve it?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685839#M24332</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-22T19:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685842#M24333</link>
      <description>&lt;P&gt;If you really just want the last one as it is sorted (or not as in this case) you can use the nosorted option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data lastzip;
  set sashelp.zipcode;
  by state county notsorted;
  if last.county;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685842#M24333</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-22T19:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685843#M24334</link>
      <description>&lt;P&gt;It did not totally fix the issue because this what the data I have already looks like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(&lt;FONT color="#FF0000"&gt;my current table - not the SASHELP.ZIPCODE table&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Denver&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jefferson&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Rifle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want to add a zip code variable to my table, and I want that zip code to be the last zip code listed in the&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;SASHELP.ZIPCODE table per the county it is in, so the final table will looks something like this. I imagine I will need to merge somehow using the last. function.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(&lt;FONT color="#339966"&gt;my new table - with the zipcode pulled from the SASHELP table&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; County&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Zip Code&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Denver&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00010&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jefferson&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Rifle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 00030&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685843#M24334</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-22T19:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685846#M24335</link>
      <description>&lt;P&gt;I'm not sure how the zipcode file is actually sorted, so I added a recnum to each record and used it to eliminate all but the last record for a given country within a state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the following will only work as intended if your state and country abbreviations/names are the same as those in the sashelp.zipcode file. That won't be the case for Rifle, CO as there is no such country in the&amp;nbsp;sashelp.zipcode file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  informat County $32. State $2.;
  input ID  County State;
  cards;
1  Denver     CO 
2  Jefferson  CO
3  Rifle      CO
;
run;

data county_zipcode;
  set sashelp.zipcode (keep=zip statecode countynm
                       rename=(statecode=state
                               countynm=county
                               zip=zip_code));
  recnum=_n_;
run;
  
proc sort data=county_zipcode;
  by state county descending recnum;
run;

proc sort data=county_zipcode nodupkey;
  by state county;
run;

data want;
  merge have(in=ina) county_zipcode (drop=recnum);
  by state county;
  if ina;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art&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>Tue, 22 Sep 2020 19:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685846#M24335</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-09-22T19:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help using SASHELP.ZIPCODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685850#M24336</link>
      <description>&lt;P&gt;Its just a merge after that.&amp;nbsp; The only trick is getting the matching variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.zipcode(where = ( statecode='CO')) out=zips;
  by statecode COUNTYNM;
run; 

data lastzip;
  set zips;
  by statecode COUNTYNM notsorted;
  if last.COUNTYNM;
run;

data mydata;
  length COUNTYNM $ 30 statecode $ 2;
  infile datalines dsd;
  input ID COUNTYNM $ statecode $;
datalines;
1,Denver,CO 
2,Jefferson,CO
3,Rifle,CO
;
run;
proc sort data=mydata;
  by statecode COUNTYNM;
run; 

data mymerged;
  merge mydata(in = wanted)
        lastzip(keep = statecode COUNTYNM zip);
  by statecode COUNTYNM;
  if wanted;
run; 
&lt;/PRE&gt;
&lt;P&gt;But note that Rifle county is not in SASHELP.ZIPCODES.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-using-SASHELP-ZIPCODE/m-p/685850#M24336</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-22T19:50:23Z</dc:date>
    </item>
  </channel>
</rss>

