<?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: Need answer if you can in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141164#M28403</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You so much Jagadish. I'm in the process of learning Macros. This is giving the correct answer to me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Nov 2013 14:20:10 GMT</pubDate>
    <dc:creator>sahaji</dc:creator>
    <dc:date>2013-11-13T14:20:10Z</dc:date>
    <item>
      <title>Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141161#M28400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I need a macro with 3 positional parameters. one is string, one is delimter and one is word number. If word number is larger than the no of words in the string, a log message has to be printed that word number is out of bounds.&lt;/P&gt;&lt;P style="margin: 0px 0px 0px 0.5in;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;call:&amp;nbsp; %test(there is a question, %str( ),1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px 0px 0px 0.5in;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;Result: there is a question&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px 0px 0px 0.5in;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;call : &lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Helv','sans-serif'; font-size: 10pt; mso-bidi-font-family: Helv;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;xscan(there is a question, %str( ),-2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px 0px 0px 0.5in;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;Result: a question&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 03:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141161#M28400</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T03:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141162#M28401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please try the below macro,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*positional parameters:*/&lt;/P&gt;&lt;P&gt;/*var=string*/&lt;/P&gt;&lt;P&gt;/*num=number of the word*/&lt;/P&gt;&lt;P&gt;/*del=delimiter*/&lt;/P&gt;&lt;P&gt;%macro test(var,num,del);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let count=%sysfunc(countw(&amp;amp;var));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let str=%sysfunc(scan("&amp;amp;var",&amp;amp;num,&amp;amp;del));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;count &amp;gt;= &amp;amp;num %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; word=scan("&amp;amp;var",&amp;amp;num,&amp;amp;del);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;str;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put "word number is out of bounds";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test(%str(ram rahul rohit),3," ")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 07:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141162#M28401</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-11-13T07:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141163#M28402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro tail(string,n,dlm);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let result_scan=%scan(&amp;amp;string,&amp;amp;n,&amp;amp;dlm);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;%if %length(&amp;amp;result_scan) %then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let result_indexw=%sysfunc(indexw(&amp;amp;string,&amp;amp;result_scan,&amp;amp;dlm));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let result=%substr(&amp;amp;string,&amp;amp;result_indexw);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;result;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %else&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put Word number is out of bounds;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend tail;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;%tail(one two three four five,2,%str( ));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%tail(one two three four five,-2,%str( ));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%tail(one two three four five,222,%str( ));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;giving:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;two three four five&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;four five&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;Word number is out of bounds&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 14:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141163#M28402</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-11-13T14:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141164#M28403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You so much Jagadish. I'm in the process of learning Macros. This is giving the correct answer to me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 14:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141164#M28403</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T14:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141165#M28404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Amir,&lt;/P&gt;&lt;P&gt;Thanks for your reply. Great effort. This one is also very helpful. Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 14:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141165#M28404</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T14:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141166#M28405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now I've one more scenario. Just need to change the above code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call:&amp;nbsp; %let sub_str = %test(this one is for learning, %str( ), -2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put The value of sub_str = &amp;amp;sub_str;&lt;/P&gt;&lt;P&gt;Result: &lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;The value of sub_str = for learning&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 14:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141166#M28405</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T14:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141167#M28406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now I've one more scenario. Just need to change the above code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call:&amp;nbsp; %let sub_str = %test(this one is for learning, %str( ), -2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put The value of sub_str = &amp;amp;sub_str;&lt;/P&gt;&lt;P&gt;Result: &lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;The value of sub_str = for learning&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 14:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141167#M28406</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T14:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141168#M28407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do want as the result with &amp;amp;POS is out of range? What about when &amp;amp;POS=0?&lt;/P&gt;&lt;P&gt;What do want when delimiter is NOT space?&lt;/P&gt;&lt;P&gt;What about multiple adjacent delimiters?&lt;/P&gt;&lt;P&gt;One way to do this is to build the result into a variable and the expand the variable as the result of the macro call.&lt;/P&gt;&lt;P&gt;Here is an example. I leave it as an exercise to see what it does with multiple adjacent delimiters and how you could change that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro test(str,dlm,pos);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%local i n top result ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=%sysfunc(countw(&amp;amp;str,&amp;amp;dlm));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if &amp;amp;pos &amp;lt; 0 %then %let top=-1 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%else %let top=&amp;amp;n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if &amp;amp;pos=0 or &amp;amp;pos &amp;gt; &amp;amp;n or &amp;amp;pos &amp;lt; -&amp;amp;n %then %let result=Out of Bounds ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%else %do i=&amp;amp;pos %to &amp;amp;top;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %if &amp;amp;i&amp;gt;&amp;amp;pos %then %let result=&amp;amp;result.&amp;amp;dlm;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let result=&amp;amp;result.%qscan(&amp;amp;str,&amp;amp;i,&amp;amp;dlm);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;amp;result.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;277&amp;nbsp; %let sub_str = "%test(this one is for learning, %str( ), -2)";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;278&amp;nbsp; %put The value of sub_str = &amp;amp;sub_str;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;The value of sub_str = "for learning"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;279&amp;nbsp; %let sub_str = "%test(this one|is|for learning,|, -2)";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;280&amp;nbsp; %put The value of sub_str = &amp;amp;sub_str;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;The value of sub_str = "is|for learning"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;281&amp;nbsp; %let sub_str = "%test(this one|is|for learning,|, 22)";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;282&amp;nbsp; %put The value of sub_str = &amp;amp;sub_str;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;The value of sub_str = "Out of Bounds"&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 16:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141168#M28407</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-13T16:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need answer if you can</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141169#M28408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You so much Tom. This is really helpful for me as I'm in the learning process of Macros. Thanks for your time and really appreciate your response.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 17:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-answer-if-you-can/m-p/141169#M28408</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-11-13T17:43:24Z</dc:date>
    </item>
  </channel>
</rss>

