<?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: How do i grab only the count, xx,  out of this xx (xx.xx)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811354#M320003</link>
    <description>&lt;P&gt;Don't use substr, because it retrieves a fixed count of characters, which creates the problem you have when you really need to accommodate a variable number of characters.&amp;nbsp; Use the SCAN function which allows you to retrieve the n'th "word" from a string - in your case you want the 1st word, where words are delimited by blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. change&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	value_n=input(substr(value, 1, 3), best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    value_n=input(scan(value,1,' '),best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Change the second argument of SCAN to 2 to get the second "word", 3 for the 3rd, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you always want the last word and you have a variable number of words in the character variable, use a negative offset, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    value_last=input(scan(value,-1,' '),best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 May 2022 03:22:44 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-05-04T03:22:44Z</dc:date>
    <item>
      <title>How do i grab only the count, xx,  out of this xx (xx.xx)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811353#M320002</link>
      <description>&lt;PRE&gt;data have1;
infile datalines dsd dlm=",";
*length value $200;
	input layer $ sort value $ 20.;
	value_n=input(substr(value, 1, 3), best.);
datalines;
001, 1, 20 (13.00)
002, 5, 35 (12.08)
003, 1, 267 (21.00)
004, 2, 28 (72.00)
005, 2, 86 (2.23)
006, 3, 24 (13.69)
007, 4, 21 (29.14)
008, 5, 7 (9.02)
009, 5, 56 (17.00)
010, 2, 21 (56.21)
;
run;&lt;/PRE&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Value is a character variable that is in the form xx (xx.xx). I'm trying to turn the xx into a new numerical variable called value_n so that i can rank it.&lt;/P&gt;
&lt;P&gt;I tried using the substr function, but as you can see, there is one 1 digit number, and 1 3 digit number that causes the problem when i extend the parameters to the first 3. When this happens the row w/ a 7 gets a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 02:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811353#M320002</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-05-04T02:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do i grab only the count, xx,  out of this xx (xx.xx)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811354#M320003</link>
      <description>&lt;P&gt;Don't use substr, because it retrieves a fixed count of characters, which creates the problem you have when you really need to accommodate a variable number of characters.&amp;nbsp; Use the SCAN function which allows you to retrieve the n'th "word" from a string - in your case you want the 1st word, where words are delimited by blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. change&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	value_n=input(substr(value, 1, 3), best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    value_n=input(scan(value,1,' '),best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Change the second argument of SCAN to 2 to get the second "word", 3 for the 3rd, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you always want the last word and you have a variable number of words in the character variable, use a negative offset, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    value_last=input(scan(value,-1,' '),best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 03:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811354#M320003</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-04T03:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do i grab only the count, xx,  out of this xx (xx.xx)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811356#M320005</link>
      <description>Thanks, worked like a charm!</description>
      <pubDate>Wed, 04 May 2022 03:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-grab-only-the-count-xx-out-of-this-xx-xx-xx/m-p/811356#M320005</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-05-04T03:20:46Z</dc:date>
    </item>
  </channel>
</rss>

