<?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: find the number of characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330435#M74130</link>
    <description>ok.i have got it.thanks for your help.</description>
    <pubDate>Tue, 07 Feb 2017 10:10:41 GMT</pubDate>
    <dc:creator>JNWong</dc:creator>
    <dc:date>2017-02-07T10:10:41Z</dc:date>
    <item>
      <title>find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330375#M74100</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;i am wondring if exists a function to count the number of character variable,not just the times which 'a refered character' appered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable values &amp;nbsp;like '' for'' ''at'' ''in'' and so on.as I have defined the length is 500,so there exists a lot of blanks ,i may try to use the compress function or strip,but it not works out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 04:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330375#M74100</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-02-07T04:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330378#M74102</link>
      <description>&lt;P&gt;The LENGTH function, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; len1=length(myvar)&lt;/P&gt;
&lt;P&gt;provides the position of the rightmost&amp;nbsp; non-blank character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; len2=length(left(myvar))&lt;/P&gt;
&lt;P&gt;does the same after left-justifying myvar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&lt;/P&gt;
&lt;P&gt;&amp;nbsp; len3=length(compress(myvar,' ',''));&lt;/P&gt;
&lt;P&gt;counts only the non-blanks.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 04:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330378#M74102</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-07T04:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330383#M74106</link>
      <description>thanks for your answers.sorry for another question&lt;BR /&gt;i use the length function to extract a string of characters indeed.&lt;BR /&gt;&lt;BR /&gt;code like: food=substr(name,find(name,var1,'i')+length(var1),32)，the variable 'name' includes the character value'var1'&lt;BR /&gt;but i can not get the right result.&lt;BR /&gt;&lt;BR /&gt;thank you</description>
      <pubDate>Tue, 07 Feb 2017 05:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330383#M74106</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-02-07T05:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330384#M74107</link>
      <description>&lt;P&gt;It would help if you provide example values of both the variables 'name' and 'var1' and what you want the value of food to be based on those values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 05:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330384#M74107</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-07T05:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330386#M74108</link>
      <description>&lt;P&gt;thank you!&lt;/P&gt;&lt;P&gt;as the 'name' variable like:&lt;/P&gt;&lt;P&gt;iphone 6 will be launched on Nov.11 2015&lt;/P&gt;&lt;P&gt;ipad mini has been introduced in Japan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var1 like;&amp;nbsp;&lt;/P&gt;&lt;P&gt;on&amp;nbsp;&lt;/P&gt;&lt;P&gt;in&lt;/P&gt;&lt;P&gt;it is just the prep in the 'name' variable.i have reverse them like'no' 'ni', var2 = reverse(var1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to extract the 'iphone' and 'ipad mini',and i have reverse the characters for substr functon.name1 = reverse(name)&lt;/P&gt;&lt;P&gt;so i use the substr like 'product = substr(name1,find(name1,var2,'i')+length(var2),32)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;athough i may not get it by one step for the other components like 'has been',&lt;/P&gt;&lt;P&gt;i just want to get 'iphone 6 will be launched'. and take other steps to drop the components 'will be launched'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&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>Tue, 07 Feb 2017 05:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330386#M74108</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-02-07T05:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330390#M74111</link>
      <description>&lt;P&gt;i have solved my problems&amp;nbsp;&lt;/P&gt;&lt;P&gt;it seems like &amp;nbsp;i have misunderstood the length of var2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;under some circumstances,it is better to use the trim function.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 06:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330390#M74111</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-02-07T06:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330423#M74121</link>
      <description>&lt;P&gt;Two things. &amp;nbsp;When posting a question post test data&amp;nbsp;&lt;STRONG&gt;in the form of a datastep&lt;/STRONG&gt; so that we can see the full picture. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, there is a function called&amp;nbsp;&lt;STRONG&gt;lengthn&lt;/STRONG&gt;. &amp;nbsp;The reason for using this function is to return the number of characters of a string with trim already done. &amp;nbsp;I.e.&lt;/P&gt;
&lt;P&gt;length(trim(&amp;lt;variable&amp;gt;))&lt;/P&gt;
&lt;P&gt;Is the same as:&lt;/P&gt;
&lt;P&gt;lengthn(&amp;lt;variable&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 09:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330423#M74121</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-07T09:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330435#M74130</link>
      <description>ok.i have got it.thanks for your help.</description>
      <pubDate>Tue, 07 Feb 2017 10:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330435#M74130</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-02-07T10:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: find the number of characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330498#M74158</link>
      <description>&lt;P&gt;It's definitely useful to discover how the length and lengthn functions work, but I think you're going about solving your problem in a round about way. I'd use the findw function. e.g.,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input @;
  name=_infile_;
cards;
iphone 6 will be launched on Nov.11 2015
ipad mini has been introduced in Japan
;

data want;
  set have;
  
  /* if you want make/model*/
  makemodel=substr(name,1,
             min(ifn(findw(name,'will',' ','s') eq 0,.,findw(name,'will',' ','s')),
                 ifn(findw(name,'has',' ','s') eq 0,.,findw(name,'has',' ','s')))-1);

  /* if you want everything before var1*/
  action=substr(name,1,
             min(ifn(findw(name,'on',' ','bs') eq 0,.,findw(name,'on',' ','bs')),
                 ifn(findw(name,'in',' ','bs') eq 0,.,findw(name,'in',' ','bs')))-1);
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 15:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-number-of-characters/m-p/330498#M74158</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-07T15:40:54Z</dc:date>
    </item>
  </channel>
</rss>

