<?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 How to get last word in given string or identify end of the string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202784#M37816</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;I was trying to make macro where I one parameter passed in, I just wanted to find how many words are passed into this and what is length of each word.&lt;/P&gt;&lt;P&gt;Like-&lt;/P&gt;&lt;P&gt;calling macro- &lt;/P&gt;&lt;P&gt;%find_len(hi this dharmendra)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;Total length of the str is(including spaces): 18&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Total length of the str is(excluding spaces): 15&lt;/P&gt;&lt;P&gt;First str is- hi and and length is: 2&lt;/P&gt;&lt;P&gt;Second str is- this and lenght is: 4&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Third str is- dharmendra and length is: 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;I have tried creating the macro but I am facing the biggest challenge is that how to get end of the string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro &lt;SPAN style="font-size: 13.3333330154419px;"&gt;find_len&lt;/SPAN&gt;(text);&lt;/P&gt;&lt;P&gt;%let len_with_space=%length(&amp;amp;text);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%let len_without_space=%length((%SYSFUNC(COMPBL(&amp;amp;text)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%local I;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let I=1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%do %UNTIL(last word of the str) ******here is the problem I do not know how to get last char or word or how identify end of the input str *************;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let word=%scan(&amp;amp;text,I,)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I=%eval(I+1);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%put &amp;amp;I str is- &amp;amp;word and length is: %lenght(&amp;amp;word);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mend find_len;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;Dharmendra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Apr 2015 20:15:45 GMT</pubDate>
    <dc:creator>LittlesasMaster</dc:creator>
    <dc:date>2015-04-23T20:15:45Z</dc:date>
    <item>
      <title>How to get last word in given string or identify end of the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202784#M37816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;I was trying to make macro where I one parameter passed in, I just wanted to find how many words are passed into this and what is length of each word.&lt;/P&gt;&lt;P&gt;Like-&lt;/P&gt;&lt;P&gt;calling macro- &lt;/P&gt;&lt;P&gt;%find_len(hi this dharmendra)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;Total length of the str is(including spaces): 18&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Total length of the str is(excluding spaces): 15&lt;/P&gt;&lt;P&gt;First str is- hi and and length is: 2&lt;/P&gt;&lt;P&gt;Second str is- this and lenght is: 4&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Third str is- dharmendra and length is: 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;I have tried creating the macro but I am facing the biggest challenge is that how to get end of the string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro &lt;SPAN style="font-size: 13.3333330154419px;"&gt;find_len&lt;/SPAN&gt;(text);&lt;/P&gt;&lt;P&gt;%let len_with_space=%length(&amp;amp;text);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%let len_without_space=%length((%SYSFUNC(COMPBL(&amp;amp;text)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%local I;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let I=1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%do %UNTIL(last word of the str) ******here is the problem I do not know how to get last char or word or how identify end of the input str *************;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let word=%scan(&amp;amp;text,I,)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I=%eval(I+1);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%put &amp;amp;I str is- &amp;amp;word and length is: %lenght(&amp;amp;word);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mend find_len;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;Dharmendra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 20:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202784#M37816</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2015-04-23T20:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last word in given string or identify end of the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202785#M37817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get a count of words with&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%sysfunc(countw(&amp;amp;string,' ,'))&lt;/P&gt;&lt;P&gt;The part ' ,' is saying what to use to separate words.&lt;/P&gt;&lt;P&gt;So&lt;/P&gt;&lt;P&gt;%let wordcount = %sysfunc(countw(&amp;amp;text,' ,'));&lt;/P&gt;&lt;P&gt;%do I = 1 %to &amp;amp;wordcount;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let word = %scan(&amp;amp;text,&amp;amp;i, ' ,'));&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;I str is- &amp;amp;word and length is: %length(&amp;amp;word);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 20:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202785#M37817</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-04-23T20:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last word in given string or identify end of the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202786#M37818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also keep with the approach you tried, but using the correct spelling of functions and using the right ones will help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro find_len(text);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let len_with_space=%length(&amp;amp;text);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let len_without_space=%length(%SYSFUNC(COMPRESS(&amp;amp;text)));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Total length of the str is (including spaces): &amp;amp;len_with_space.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Total length of the str is (excluding spaces): &amp;amp;len_without_space.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let I=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do %while(%length(%scan(&amp;amp;text,&amp;amp;I.,' ')) gt 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let word=%scan(&amp;amp;text,&amp;amp;I.,' ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;I str is- &amp;amp;word and length is: %length(&amp;amp;word);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let I=%eval(&amp;amp;I.+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend find_len;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%find_len(hi this dharmendra here)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 21:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202786#M37818</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-23T21:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last word in given string or identify end of the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202787#M37819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Arthur,&lt;/P&gt;&lt;P&gt;Thank you for your reply on this, it helped me.&lt;/P&gt;&lt;P&gt;Just curious&amp;nbsp; to know what is correct use of the Dot after the I variable?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have always used Dot like working with something post fix like this&lt;/P&gt;&lt;P&gt;X1 X2 X3 X4&lt;/P&gt;&lt;P&gt;so i use X.&amp;amp;I&lt;/P&gt;&lt;P&gt;and I will start from 1 to 4 likewise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me understand this concept here?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Apr 2015 17:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202787#M37819</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2015-04-25T17:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last word in given string or identify end of the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202788#M37820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The dot, as I used it, was simply a delimiter to indicate the end of a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The documentation states: &lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; font-size: 13.4399995803833px; background-color: #ffffff;"&gt;A period immediately following a macro variable reference acts as a delimiter. That is, a period at the end of a reference forces the macro processor to recognize the end of the reference. The period does not appear in the resulting text.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Most of the time it isn't needed, but sometimes it is absolutely essential. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case you mentioned, I would have used X&amp;amp;i.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Apr 2015 18:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-word-in-given-string-or-identify-end-of-the/m-p/202788#M37820</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-25T18:31:12Z</dc:date>
    </item>
  </channel>
</rss>

