<?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: Recoding a variable with first 3 characters of a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312144#M67655</link>
    <description>&lt;P&gt;Ok...basically you need to nest a bunch of functions to get what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Character functions that you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SUBSTR() -&amp;gt; takes a substring of character variable&lt;/P&gt;
&lt;P&gt;CATX() -&amp;gt; concatenates variables, with a specified delimiter&lt;/P&gt;
&lt;P&gt;IFN() -&amp;gt; Can be used to check for missing and replace with NA&lt;/P&gt;
&lt;P&gt;PUT() -&amp;gt; Convert numeric to character variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think those 4 will get you want you need in some combination.&lt;/P&gt;
&lt;P&gt;You can play around with them to get your result.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2016 22:35:57 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-11-16T22:35:57Z</dc:date>
    <item>
      <title>Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312024#M67621</link>
      <description>Hi there,&lt;BR /&gt;&lt;BR /&gt;I am looking to create a new variable that is a composite of the first three characters of a string variable (they are names) with an underscore and then an associated numeric variable. I was planning on using the trim function but cannot figure out how to crop the first three letters off of the string variable. any suggestions?&lt;BR /&gt;&lt;BR /&gt;Thanks very much!</description>
      <pubDate>Wed, 16 Nov 2016 16:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312024#M67621</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T16:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312028#M67622</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking a guess at your data (as you have not put test data in the form of a datastep here so that we have something to work with):&lt;/P&gt;
&lt;PRE&gt;data want;
  charvar="XYZDEFGH";
  numvar=43256;
  result=catx("_",substr(charvar,1,3),put(numvar,best.));
run;&lt;/PRE&gt;
&lt;P&gt;Substr is the function to get the characters you want, put() is the function to show numbers as text, and catx concatenates text with a delimiter, in this case "_".&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 16:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312028#M67622</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-16T16:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312039#M67623</link>
      <description>&lt;P&gt;What will your rule be if the name only has 1 or&amp;nbsp;2 characters? Do you need&amp;nbsp; _ to make a fixed length or will 1 or 2 characters followed by a single _ suffice?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 16:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312039#M67623</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T16:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312063#M67624</link>
      <description>Hey,&lt;BR /&gt;&lt;BR /&gt;Thanks! Full disclosure I'm a student new to SAS so forgive my confusion.&lt;BR /&gt;In your example, is XYZDEFGH the name of the variable? I tried it but it&lt;BR /&gt;told me the numerical variable was uninitialized.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 16 Nov 2016 18:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312063#M67624</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T18:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312065#M67625</link>
      <description>Hey,&lt;BR /&gt;&lt;BR /&gt;Upon inspection, none of the string variables have fewer than 3 characters&lt;BR /&gt;so a fixed number should work I think!&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 16 Nov 2016 18:29:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312065#M67625</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T18:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312082#M67626</link>
      <description>&lt;P&gt;Right of an = is the value, left is the name of the variable.&lt;/P&gt;
&lt;P&gt;So the statement&lt;/P&gt;
&lt;P&gt;charvar="XYZDEFGH";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creates a varaible named Charvar and assigns the value of XYZDEFGH.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 19:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312082#M67626</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T19:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312083#M67627</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115382"&gt;@smashing﻿&lt;/a&gt;&amp;nbsp;If you have an answer please mark the question solved. If you still need help please post some samples of what your observation looks like and what you want as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are probably several methods to do this so if you want alternate solutions you should post sample data anyways.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 19:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312083#M67627</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-16T19:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312093#M67631</link>
      <description>&lt;BR /&gt;Ah, OK...was envisioning not copying all of the values in as I worried it would be unyielding. Here's my data--I'm looking to get the first 3 letters of name and lifeex76 together:&lt;BR /&gt;&lt;BR /&gt;Obs name lifeex76 urpop76 indeat70 t1rnd&lt;BR /&gt;1 Algeria 55 40.3 150 40&lt;BR /&gt;2 Angola 39 17.8 186 18&lt;BR /&gt;3 Benin 41 21.5 160 22&lt;BR /&gt;4 Botswana 52 12.0 110 12&lt;BR /&gt;5 Burkina Faso 42 6.3 185 6&lt;BR /&gt;6 Burundi 45 3.0 140 3&lt;BR /&gt;7 Cameroon 46 26.9 136 27&lt;BR /&gt;8 Cape Verde . 30.2 120 30&lt;BR /&gt;9 Central African Rep 42 34.2 160 34&lt;BR /&gt;10 Chad 40 15.2 179 15&lt;BR /&gt;11 Comoros . 21.3 115 21&lt;BR /&gt;12 Congo 44 35.8 110 36&lt;BR /&gt;13 Cote d'Ivoire 47 32.2 143 32&lt;BR /&gt;14 Djibouti . 68.5 166 69&lt;BR /&gt;15 Egypt 54 43.5 170 44&lt;BR /&gt;16 Equatorial Guinea . 46.6 173 47&lt;BR /&gt;17 Ethiopia 42 9.5 162 10&lt;BR /&gt;18 Gabon 46 30.6 147 31&lt;BR /&gt;19 Gambia . 16.6 193 17&lt;BR /&gt;20 Ghana 51 29.8 117 30&lt;BR /&gt;21 Guinea-Bissau . 20.8 173 21&lt;BR /&gt;22 Guinea 37 16.3 192 16&lt;BR /&gt;23 Kenya 52 12.9 108 13&lt;BR /&gt;24 Lesotho 50 10.8 140 11&lt;BR /&gt;25 Liberia 49 30.4 132 30&lt;BR /&gt;26 Libya 54 46.8 130 47&lt;BR /&gt;27 Madagascar 48 16.3 195 16&lt;BR /&gt;28 Malawi 42 7.7 197 8&lt;BR /&gt;29 Mali 39 16.2 206 16&lt;BR /&gt;30 Mauritania 41 19.6 173 20&lt;BR /&gt;31 Mauritius 64 43.6 67 44&lt;BR /&gt;32 Morocco 54 37.8 138 38&lt;BR /&gt;33 Mozambique, People's Rep 43 8.6 175 9&lt;BR /&gt;34 Namibia 50 . . .&lt;BR /&gt;35 Niger 40 10.6 176 11&lt;BR /&gt;36 Nigeria 46 23.4 172 23&lt;BR /&gt;37 Rwanda 45 4.0 140 4&lt;BR /&gt;38 Senegal 41 34.2 168 34&lt;BR /&gt;39 Sierra Leone 36 21.1 204 21&lt;BR /&gt;40 Somalia 42 25.6 162 26&lt;BR /&gt;41 South Africa 55 50.5 120 51&lt;BR /&gt;42 Sudan 44 18.9 156 19&lt;BR /&gt;43 Swaziland . 14.0 147 14&lt;BR /&gt;44 Tanzania 48 10.1 135 10&lt;BR /&gt;45 Togo 47 15.8 141 16&lt;BR /&gt;46 Tunisia 58 47.6 138 48&lt;BR /&gt;47 Uganda 48 8.3 118 8&lt;BR /&gt;48 Zaire 47 32.2 137 32&lt;BR /&gt;49 Zambia 48 36.3 115 36&lt;BR /&gt;50 Zimbabwe 53 19.4 101 19&lt;BR /&gt;51 Barbados . 38.6 33 39&lt;BR /&gt;52 Canada 74 75.6 21 76&lt;BR /&gt;53 Costa Rica 69 42.2 66 42&lt;BR /&gt;54 Cuba 72 64.2 49 64&lt;BR /&gt;55 Dominican Rep 61 45.3 105 45&lt;BR /&gt;56 El Salvador 58 40.4 112 40&lt;BR /&gt;57 Guatemala 55 37.1 108 37&lt;BR /&gt;58 Haiti 50 22.1 172 22&lt;BR /&gt;59 Honduras 56 32.3 123 32&lt;BR /&gt;60 Jamaica 68 44.1 45 44&lt;BR /&gt;61 Mexico 64 62.8 79 63&lt;BR /&gt;62 Nicaragua 55 50.3 115 50&lt;BR /&gt;63 Panama 68 49.1 52 49&lt;BR /&gt;64 Trinidad and Tobago 67 48.4 41 48&lt;BR /&gt;65 United States 72 73.6 22 74&lt;BR /&gt;66 Argentina 68 80.6 56 81&lt;BR /&gt;67 Bolivia 48 41.5 157 42&lt;BR /&gt;68 Brazil 61 61.8 100 62&lt;BR /&gt;69 Chile 65 78.3 95 78&lt;BR /&gt;70 Colombia 61 60.8 74 61&lt;BR /&gt;71 Ecuador 60 42.4 107 42&lt;BR /&gt;72 Guyana . 29.6 56 30&lt;BR /&gt;73 Paraguay 66 39.0 67 39&lt;BR /&gt;74 Peru 56 61.4 126 61&lt;BR /&gt;75 Suriname . 44.8 55 45&lt;BR /&gt;76 Uruguay 69 83.0 48 83&lt;BR /&gt;77 Venezuela 67 77.8 60&lt;BR /&gt;78&lt;BR /&gt;&lt;BR /&gt;Thanks for all your help!&lt;BR /&gt;Show quoted text&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2016 19:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312093#M67631</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T19:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312098#M67633</link>
      <description>&lt;P&gt;You didn't post what you wanted as output, but a CATT should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want = CATT(substr(name, 1, 3), lifeex76);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATT converts numerics to character and SUBSTR takes the first 3 characters of the name.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 20:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312098#M67633</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-16T20:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312108#M67638</link>
      <description>&lt;P&gt;Your data has missing values for lifeex76 for observations 8, 11, 14, 16 and others. What is the rule for those? Your current rule would possibly yield something like Cap_. for Cape Verde.&lt;/P&gt;
&lt;P&gt;Also your observation 56 would yield "El _58" with a space betwee the "l" and the "_". Is that going to be the desired result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to provide some examples of how the constructed variable is to be used to get better suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 20:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312108#M67638</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T20:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312111#M67640</link>
      <description>Good catch with the El...yeah, that's not what I want.&lt;BR /&gt;&lt;BR /&gt;In terms of the missing, I'm converting missing values to NA with:&lt;BR /&gt;&lt;BR /&gt;if lifeex76 eq . then l&lt;BR /&gt;lifeex76='NA';&lt;BR /&gt;&lt;BR /&gt;(It's what is requested in my homework)&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 16 Nov 2016 20:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312111#M67640</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T20:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312121#M67642</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That almost works but I need an underscore between the two values and adding a , '_' , doesn't seem to work. It&amp;nbsp;says substr has too many arguments.&amp;nbsp;&amp;nbsp;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 21:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312121#M67642</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T21:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312123#M67644</link>
      <description>&lt;P&gt;Incidentially, my attempt to replace . with NA doesn't seem to work--getting this outpu:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name=Guinea-Bissau lifeex76=. urpop76=20.8 indeat70=173 _ERROR_=1 _N_=21&lt;BR /&gt;NOTE: Invalid numeric data, 'NA' , at line 175 column 32.&lt;BR /&gt;name=Swaziland lifeex76=. urpop76=14 indeat70=147 _ERROR_=1 _N_=43&lt;BR /&gt;NOTE: Invalid numeric data, 'NA' , at line 175 column 32.&lt;BR /&gt;name=Barbados lifeex76=. urpop76=38.6 indeat70=33 _ERROR_=1 _N_=51&lt;BR /&gt;NOTE: Invalid numeric data, 'NA' , at line 175 column 32.&lt;BR /&gt;name=Guyana lifeex76=. urpop76=29.6 indeat70=56 _ERROR_=1 _N_=72&lt;BR /&gt;NOTE: Invalid numeric data, 'NA' , at line 175 column 32.&lt;BR /&gt;name=Suriname lifeex76=. urpop76=44.8 indeat70=55 _ERROR_=1 _N_=75&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 21:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312123#M67644</guid>
      <dc:creator>smashing</dc:creator>
      <dc:date>2016-11-16T21:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312129#M67646</link>
      <description>&lt;P&gt;This is why you show the output you want...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATX instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATX("_", substr..., othervariable)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 21:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312129#M67646</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-16T21:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312141#M67652</link>
      <description>&lt;P&gt;SAS will not allow character values for numeric variables. So "NA" being letters do not work. However SAS does provide for the display of special text for a missing value by use of a custom&amp;nbsp;display format.&lt;/P&gt;
&lt;P&gt;run this:&lt;/P&gt;
&lt;P&gt;Proc format library=work;&lt;/P&gt;
&lt;P&gt;value Lifeex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;. = 'NA'&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your data step add the line:&lt;/P&gt;
&lt;P&gt;Format Lifeex76 Lifeex. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the value NA will appear for missing values. You will either need to run the Proc Format code every session or dig into the field of pernament libraries, format catalogs and format search paths.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should provide what you want for the EL Salavador data.&lt;/P&gt;
&lt;P&gt;It may be you are looking for something like&lt;/P&gt;
&lt;P&gt;result = catx('_',substr(scan(name,1),1,3),put(lifeex76,lifeex.));&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 22:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312141#M67652</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T22:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312142#M67653</link>
      <description>&lt;P&gt;SAS will not allow character values for numeric variables. So "NA" being letters do not work. However SAS does provide for the display of special text for a missing value by use of a custom&amp;nbsp;display format.&lt;/P&gt;
&lt;P&gt;run this:&lt;/P&gt;
&lt;P&gt;Proc format library=work;&lt;/P&gt;
&lt;P&gt;value Lifeex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;. = 'NA'&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your data step add the line:&lt;/P&gt;
&lt;P&gt;Format Lifeex76 Lifeex. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the value NA will appear for missing values. You will either need to run the Proc Format code every session or dig into the field of pernament libraries, format catalogs and format search paths.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should provide what you want for the EL Salavador data.&lt;/P&gt;
&lt;P&gt;It may be you are looking for something like&lt;/P&gt;
&lt;P&gt;result = catx('_',substr(scan(name,1),1,3),put(lifeex76,lifeex.));&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 22:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312142#M67653</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T22:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312144#M67655</link>
      <description>&lt;P&gt;Ok...basically you need to nest a bunch of functions to get what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Character functions that you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SUBSTR() -&amp;gt; takes a substring of character variable&lt;/P&gt;
&lt;P&gt;CATX() -&amp;gt; concatenates variables, with a specified delimiter&lt;/P&gt;
&lt;P&gt;IFN() -&amp;gt; Can be used to check for missing and replace with NA&lt;/P&gt;
&lt;P&gt;PUT() -&amp;gt; Convert numeric to character variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think those 4 will get you want you need in some combination.&lt;/P&gt;
&lt;P&gt;You can play around with them to get your result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 22:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312144#M67655</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-16T22:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding a variable with first 3 characters of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312272#M67706</link>
      <description>&lt;P&gt;Well, I see you guys have been busy overnight! &amp;nbsp;For my 2p worth I would wrap in a tranwrd() to get the NA - I tend to avoid formats as much as possible. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  length result $50;
  infile datalines missover;
  input obs name $ lifeex76;
  result=tranwrd(catx("_",substr(name,1,3),put(lifeex76,best.)),".","NA");
datalines;
1 Algeria 55
2 Angola 
;
run;
&lt;/PRE&gt;
&lt;P&gt;You could of course drop the put() statement, however then you would get notes in the log about number to char conversions - I would always put() personally as it is explicit what you are doing there. &amp;nbsp;Remember coding is not so much about writing fantastically fast and complicated code, but making it simple for the next person to understand what you have coded.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 10:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-a-variable-with-first-3-characters-of-a-string/m-p/312272#M67706</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-17T10:45:06Z</dc:date>
    </item>
  </channel>
</rss>

