<?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 Convert Full State Name to Abbreviation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738723#M230474</link>
    <description>&lt;P&gt;It looks like SAS has built in function to convert from State FIPS to full state name and abbreviation to full state name but I can't find one to go from full state name to abbreviation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     input state $50.;
cards;
Alabama
Alaska
Arizona
;;;;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit: Want:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;&lt;STRONG&gt;State&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;&lt;STRONG&gt;Abbreviation&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Alabama&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;Al&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Alaska&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;AK&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Arizona&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;AZ&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 04 May 2021 00:15:30 GMT</pubDate>
    <dc:creator>SAShole</dc:creator>
    <dc:date>2021-05-04T00:15:30Z</dc:date>
    <item>
      <title>Convert Full State Name to Abbreviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738723#M230474</link>
      <description>&lt;P&gt;It looks like SAS has built in function to convert from State FIPS to full state name and abbreviation to full state name but I can't find one to go from full state name to abbreviation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     input state $50.;
cards;
Alabama
Alaska
Arizona
;;;;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit: Want:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;&lt;STRONG&gt;State&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;&lt;STRONG&gt;Abbreviation&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Alabama&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;Al&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Alaska&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;AK&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;Arizona&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;AZ&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 04 May 2021 00:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738723#M230474</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2021-05-04T00:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Full State Name to Abbreviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738741#M230483</link>
      <description>&lt;P&gt;There is a function to convert the code into a name like that.&lt;/P&gt;
&lt;P&gt;So use that to make an informat you can use to convert the name to fips code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fips;
  fmtname='FIPS';
  type='I';
  length label 8 start $20 ;
  do label=1 to 95;
    start=fipnamel(label);
    if start ne 'Invalid Code' then output;
  end;
run;

proc format cntlin=fips ; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's use the FIPS dataset we just made&amp;nbsp; to test the new informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set fips;
 fipscode=input(start,fips.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    fmtname    type    label    start                   fipscode

  1     FIPS       I         1     Alabama                     1
  2     FIPS       I         2     Alaska                      2
  3     FIPS       I         4     Arizona                     4
  4     FIPS       I         5     Arkansas                    5
  5     FIPS       I         6     California                  6
  6     FIPS       I         8     Colorado                    8
  7     FIPS       I         9     Connecticut                 9
  8     FIPS       I        10     Delaware                   10
  9     FIPS       I        11     District of Columbia       11
 10     FIPS       I        12     Florida                    12
...&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 May 2021 23:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738741#M230483</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-03T23:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Full State Name to Abbreviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738750#M230488</link>
      <description>I'm actually looking to convert to the abbreviation. Apologies, as I think I confused the question by mentioned FIPS code.</description>
      <pubDate>Tue, 04 May 2021 00:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738750#M230488</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2021-05-04T00:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Full State Name to Abbreviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738775#M230497</link>
      <description>&lt;P&gt;Then you just need to add another function call to the code to generate the date for the format.&lt;/P&gt;
&lt;P&gt;Since you are now mapping character to character you can use either a format and the PUT() function or a character informat and the INPUT() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fips;
  fmtname='$FIPS';
  length fips 8 label $2 start $20 ;
  do fips=1 to 95;
    start=fipnamel(fips);
    if start ne 'Invalid Code' then do;
       label=fipstate(fips);
       output;
    end;
  end;
run;

proc format cntlin=fips ; run;

data test;
 set fips;
 statecode=put(start,$fips.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 May 2021 03:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Full-State-Name-to-Abbreviation/m-p/738775#M230497</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-04T03:29:22Z</dc:date>
    </item>
  </channel>
</rss>

