<?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 recode text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412285#M100830</link>
    <description>&lt;P&gt;Dear community members&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my first post, so I hope my explanation is useful. I am trying to recode a character variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset called "Wages", a variable called "Level" and in this variable I wish to recode each observation "Level 01" to "01" instead, so that I can later change the variable to a numeric one. Basically, instead of having data with numbers and labels that go with these numbers, I have data where each category is represented by text instead, so I guess I have to do a lot&amp;nbsp;of work to recode all this data and put on labels afterwards before I can start analysing my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how do I recode observations while keeping all the other data in my datasheet?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use SCAN, SUBSTR and PROC SQL but I'm not really getting anywhere. I am getting errors or empty datasheets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jacob&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Nov 2017 12:19:12 GMT</pubDate>
    <dc:creator>Jbraun</dc:creator>
    <dc:date>2017-11-10T12:19:12Z</dc:date>
    <item>
      <title>recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412285#M100830</link>
      <description>&lt;P&gt;Dear community members&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my first post, so I hope my explanation is useful. I am trying to recode a character variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset called "Wages", a variable called "Level" and in this variable I wish to recode each observation "Level 01" to "01" instead, so that I can later change the variable to a numeric one. Basically, instead of having data with numbers and labels that go with these numbers, I have data where each category is represented by text instead, so I guess I have to do a lot&amp;nbsp;of work to recode all this data and put on labels afterwards before I can start analysing my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how do I recode observations while keeping all the other data in my datasheet?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use SCAN, SUBSTR and PROC SQL but I'm not really getting anywhere. I am getting errors or empty datasheets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jacob&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 12:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412285#M100830</guid>
      <dc:creator>Jbraun</dc:creator>
      <dc:date>2017-11-10T12:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412295#M100835</link>
      <description>&lt;P&gt;I all you want to do is to extract only the numbers in your Level character&amp;nbsp;variabel and convert them to numeric, this may get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input level$1-8 var1 var2;
datalines;
level 01 10 20
level 01 10 40
level 02 10 50
level 03 20 50
level 03 30 20
level 04 30 70
level 04 30 90
;

data want;
	set have;
	num_level=input(compress(level, '', 'kd'), best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Nov 2017 12:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412295#M100835</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-10T12:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412296#M100836</link>
      <description>&lt;P&gt;The COMPRESS function can do this easily:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;level = compress(level, , 'kd' ) ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will keep just the digits.&amp;nbsp; However, depending on what is in your data, this may be too simple.&amp;nbsp; You will end up with "01" if your original value is any of these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Level 01&lt;/P&gt;
&lt;P&gt;Level 0-1&lt;/P&gt;
&lt;P&gt;Level 0.1&lt;/P&gt;
&lt;P&gt;Level 0, Sublevel 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 12:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412296#M100836</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-10T12:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412670#M100933</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;very much for your answers. I'm sorry, but I should have specified more clearly: Some of the recodes will not be to just extract the digits. With some observations I have only text which I want to give a number so that I can put a label on that number and do statistical analysis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Jacob&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 09:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412670#M100933</guid>
      <dc:creator>Jbraun</dc:creator>
      <dc:date>2017-11-12T09:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412674#M100935</link>
      <description>&lt;P&gt;Please post some example of how your data would look if you want a code answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 10:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412674#M100935</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-12T10:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412988#M101029</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163039"&gt;@Jbraun&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&amp;nbsp;very much for your answers. I'm sorry, but I should have specified more clearly: Some of the recodes will not be to just extract the digits. With some observations I have only text which I want to give a number so that I can put a label on that number and do statistical analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Jacob&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Provide examples. If the list of values does not change very often perhaps a custom informat will help.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 18:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/412988#M101029</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-13T18:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413403#M101168</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;Ok, let me try Again. Below I have tried to explain what my data looks like. I don't have numeric data in my variables, but character variables. The code below would not Work, obviously, but I can't upload the actual data, so I am hoping you understand. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;When it says "Level 01" I want to recode to a number, such as "1"&amp;nbsp;that I can give a label "Level 01" so that I am dealing with numbers representing categories instead of character observations, since SAS doesn't handle that very well. &lt;/FONT&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Wages;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Level;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Level 01&lt;/P&gt;&lt;P&gt;Other&lt;/P&gt;&lt;P&gt;Bla.bla.&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 16:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413403#M101168</guid>
      <dc:creator>Jbraun</dc:creator>
      <dc:date>2017-11-14T16:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413408#M101170</link>
      <description>&lt;P&gt;Why does it matter if your categorical variable is numeric or character?&lt;/P&gt;
&lt;P&gt;What procedure are you trying to use where it makes a difference?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 17:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413408#M101170</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-14T17:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: recode text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413423#M101178</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because 'kd' (keep digits) was suggested, and some of my recodes will not be to just extrapolate digits&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 17:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recode-text/m-p/413423#M101178</guid>
      <dc:creator>Jbraun</dc:creator>
      <dc:date>2017-11-14T17:48:38Z</dc:date>
    </item>
  </channel>
</rss>

