<?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 Update the missing variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225616#M40518</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The attached dataset contains the missing "state" and "stateab". These two variables can be matched with the "STCOD".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone suggest a program that can help me to update the missing variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;</description>
    <pubDate>Tue, 15 Sep 2015 15:14:15 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2015-09-15T15:14:15Z</dc:date>
    <item>
      <title>Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225616#M40518</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The attached dataset contains the missing "state" and "stateab". These two variables can be matched with the "STCOD".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone suggest a program that can help me to update the missing variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 15:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225616#M40518</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-15T15:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225635#M40525</link>
      <description>Have you tried a merge?</description>
      <pubDate>Tue, 15 Sep 2015 15:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225635#M40525</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-15T15:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225640#M40526</link>
      <description>&lt;P&gt;Hi ... you can use functions ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data fixed;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set z.full;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if missing(state) then do;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;state = fipname(stcod);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;stateab = fipstate(stcod);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the variable COUNTY has three different forms in the data set: &amp;nbsp;just the county name, county + state, county name followed by the word "County". &amp;nbsp;. Why not make it consistent, just the county name ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data fixed;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set z.full;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if missing(state) then do;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;state = fipname(stcod);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;stateab = fipstate(stcod);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* get rid of the STATE, get rid of text 'COUNTY';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if find(county,',') then county=scan(county,1,',');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if findw(county,'County') then county = tranwrd(county,'County',' ');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 16:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225640#M40526</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-09-15T16:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225685#M40532</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your dataset is pretty small, so a PROC SQL update statement would work nicely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first step involves creating a lookup table; I included a frequency column (informational only and not needed). But notice that for our nation's capital, there are two spelling variations (&lt;SPAN&gt;"District &lt;STRONG&gt;of&lt;/STRONG&gt; Columbia" and&amp;nbsp;"District &lt;STRONG&gt;Of&lt;/STRONG&gt;&amp;nbsp;Columbia"). The PROC SORT gets rid of the duplicate.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Next, a series of two PROC SQL update statement updates rows for which state is missing and then&amp;nbsp;updates rows for which stateab is missing. Since your dataset is relatively small, an "in-place"&amp;nbsp;PROC SQL update works just fine. If your dataset were much larger with millions of observations, then a PROC SQL update may be suboptimal.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* first, create a lookup table */
PROC SQL;
  CREATE TABLE distinct_states AS 
  SELECT STCOD, state, stateab, COUNT(*) as state_frequency
  FROM full
  WHERE NOT MISSING(state)
  GROUP BY STCOD, state, stateab
  ORDER BY 2, 1, 4 DESC;
QUIT;


/* note that your dataset has District of Columbia spelled two different 
   ways, thus get rid of one of them */
PROC SORT DATA=distinct_states nodupkey;
  BY STCOD;
RUN;


PROC SQL;
/* only update where state is missing */
  UPDATE full
  SET state = (SELECT MAX(state)
               FROM distinct_states
               WHERE full.STCOD = distinct_states.STCOD)
  WHERE MISSING(state);
QUIT;


PROC SQL;
/* only update where abbreviated state is missing */
  UPDATE full
  SET stateab = (SELECT MAX(stateab)
                 FROM distinct_states
                 WHERE full.STCOD = distinct_states.STCOD)
  WHERE MISSING(stateab);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 19:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225685#M40532</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-09-15T19:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225693#M40535</link>
      <description>&lt;P&gt;Hi. &amp;nbsp;There are functions to convert state codes (fips numbers) to state names and two character abbreviations. &amp;nbsp;Every observation in the data set has a state code.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 19:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225693#M40535</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-09-15T19:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225757#M40561</link>
      <description>&lt;P&gt;Dear Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I tried. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 04:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225757#M40561</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-16T04:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225758#M40562</link>
      <description>&lt;P&gt;Dear MikeZded,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you mean that SAS system contains a database of state codes, with their names and abbreviation? May I know which SAS function can perform this procedure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 04:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225758#M40562</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-16T04:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225759#M40563</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. I read your suggested program. I think this only works for U.S. data. Do you think this is applicable to other countries as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 04:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225759#M40563</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-16T04:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225760#M40564</link>
      <description>Thanks MikeZded and hbi for your programs. Both are the correct solution.</description>
      <pubDate>Wed, 16 Sep 2015 04:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225760#M40564</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-16T04:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update the missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225827#M40580</link>
      <description>&lt;P&gt;Correct, the various functions that deal with state and zip codes are US only. &amp;nbsp;There are a lot of such functions&amp;nbsp;(see below from SAS online HELP). &amp;nbsp;Also the SQL solution for US state codes worked fine, but given that there are two functions that did the same thing,in two statements,&amp;nbsp;it seems like a lot of code for US-based data. &amp;nbsp;However , it would be a solution for an instance when functions would not work, e.g. non-US data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;State and Zip Code Functions&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;FIPNAME&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts FIPS codes to uppercase state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;FIPNAMEL&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts FIPS codes to mixed-case state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;FIPSTATE &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts FIPS codes to two-character postal codes &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;GEODISTANCE &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;returns the geodetic distance between two latitude and longitude coordinates&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;STFIPS &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts state postal codes to FIPS state codes &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;STNAME &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts state postal codes to uppercase state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;STNAMEL &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts state postal codes to mixed-case state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPCITY &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;returns a city name and the two-character postal code that corresponds to a zip code &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPCITYDISTANCE &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;returns the geodetic distance between two zip code locations &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPFIPS &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts zip codes to FIPS state codes &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPNAME &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts zip codes to uppercase state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPNAMEL &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts zip codes to mixed-case state names &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ZIPSTATE &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;converts zip codes to state postal codes&lt;/STRONG&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 13:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-missing-variables/m-p/225827#M40580</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-09-16T13:24:30Z</dc:date>
    </item>
  </channel>
</rss>

