<?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 cannot split variable into character and numerical variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767302#M243252</link>
    <description>&lt;P&gt;The Taster variable is made up of number(XX)and gender(M/F). For example, 32F (no blank between) and 31M. Here is my code,&amp;nbsp; this does not have an error but the new variable rows,subj_gender, and subj_age, are empty. My aim is to have gender and age variables, which split from the Taster variable.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;data wineA2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;set wineA;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_char = Taster;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_gender = subject;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_age = subject+0;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; drop Taster;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; run;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;proc print data=wineA2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 03:05:43 GMT</pubDate>
    <dc:creator>shimengj</dc:creator>
    <dc:date>2021-09-13T03:05:43Z</dc:date>
    <item>
      <title>cannot split variable into character and numerical variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767302#M243252</link>
      <description>&lt;P&gt;The Taster variable is made up of number(XX)and gender(M/F). For example, 32F (no blank between) and 31M. Here is my code,&amp;nbsp; this does not have an error but the new variable rows,subj_gender, and subj_age, are empty. My aim is to have gender and age variables, which split from the Taster variable.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;data wineA2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;set wineA;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_char = Taster;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_gender = subject;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; subj_age = subject+0;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; drop Taster;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; run;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;proc print data=wineA2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 03:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767302#M243252</guid>
      <dc:creator>shimengj</dc:creator>
      <dc:date>2021-09-13T03:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: cannot split variable into character and numerical variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767303#M243253</link>
      <description>&lt;P&gt;I noticed that the "subject" should be "Taster". I ran the new code, subj_age is still empty and subj_gender has data. However, subj_gender still has character and numerical data.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 03:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767303#M243253</guid>
      <dc:creator>shimengj</dc:creator>
      <dc:date>2021-09-13T03:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: cannot split variable into character and numerical variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767305#M243254</link>
      <description>&lt;P&gt;Actual values in the form of data step code are the best way to provide example data.&lt;/P&gt;
&lt;P&gt;The following creates a small data set using a data step to create the two values you mention and then separate them.&lt;/P&gt;
&lt;PRE&gt;data have;
  input taster $;
datalines;
32F
31M
;

data want;
   set have;
   sub_age = input(compress(taster,,'DK'),f5.);
   sub_gender=compress(taster,,'D');
run;&lt;/PRE&gt;
&lt;P&gt;The Compress function removes (or keeps) lists of characters present in your value. In this case no list is provided as the option 'D' indicates digit characters. In the first line the&amp;nbsp; K coupled with D keeps digits. Then the input function is used to create the numeric value. The second drops all Digit characters to leave the gender.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: while it will work sometimes the use of +0 to make a numeric value is subject to implied conversions, in this case none because you used the whole value and F or M are not going to turn into numeric values with the simple conversion of text to number rules.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 04:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767305#M243254</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-13T04:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: cannot split variable into character and numerical variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767307#M243255</link>
      <description>&lt;P&gt;Are you saying that "32F" represents a 32-year-old female?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then (untested due to absence of a working data set):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wineA2;
  set wineA;
  length subj_gender $1;
  subj_gender=char(taster,length(taster));
  subj_age=input(translate(taster,'',subj_gender),best3.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The TRANSLATE function converts any character equal to SUBJ_GENDER to a blank.&amp;nbsp; &amp;nbsp;The INPUT function uses the BEST3. informat to allow for 100-year-old tasters.&amp;nbsp; Otherwise BEST2. would do.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 04:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767307#M243255</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-13T04:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: cannot split variable into character and numerical variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767312#M243259</link>
      <description>&lt;P&gt;The INPUT() function does not care if you use a width on the INFORMAT that is longer than the length of the string you are reading.&amp;nbsp; The maximum width for the normal numeric informat is 32.&amp;nbsp; So just use an informat specification of:&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;32.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: BEST is the name of a FORMAT.&amp;nbsp; There is no BEST informat. If you do use that name as an informat then SAS will assume you meant to use the normal numeric informat.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 04:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cannot-split-variable-into-character-and-numerical-variables/m-p/767312#M243259</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-13T04:28:53Z</dc:date>
    </item>
  </channel>
</rss>

