<?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: %scan and %nrbquote in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301495#M63821</link>
    <description>&lt;P&gt;Thx to all! My problem's solved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do all text transformations in data step is a really good idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But because scan function cuts very large text (i think it has limit for one 'word'), i use substr(text, index_select, index_delim - index_select) where index_select is index of 'select' word and index_delim is index of ';'.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2016 11:31:29 GMT</pubDate>
    <dc:creator>grozzik</dc:creator>
    <dc:date>2016-09-29T11:31:29Z</dc:date>
    <item>
      <title>%scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301480#M63812</link>
      <description>&lt;P&gt;Hello, experts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable text, that contains string '%let blablabla select * from tablename where blablabla; asdsad'.&lt;/P&gt;&lt;P&gt;And i want to cut all before word 'select' and after first semicolon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try next statements:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let text2 = %scan(%nrbquote(&amp;amp;text), 1, %str(; ));&lt;/P&gt;&lt;P&gt;%let ind = %index(%qupcase(&amp;amp;text2), SELECT);&lt;/P&gt;&lt;P&gt;%let cut_text = %substr(%nrbquote(&amp;amp;text2), &amp;amp;ind);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And after %scan function my variable text2 contains nothing judging by log. If i try another string in text (for example '%%asd select ...;') it works, but with %let at start doesn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which function have i to use instead %nrbquote and&amp;nbsp;%scan? Help me plz)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 10:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301480#M63812</guid>
      <dc:creator>grozzik</dc:creator>
      <dc:date>2016-09-29T10:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301482#M63813</link>
      <description>&lt;P&gt;Why are you putting code in a macro variable? &amp;nbsp;To my mind you are opening a whole can of worms. &amp;nbsp;Code can contain any number of special characters, syntax etc. all of which will break macro. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find that doing this data processing is far easier in Base SAS, macro is never simpler and always makes more complicated code:&lt;/P&gt;
&lt;PRE&gt;data want;
  tmp='%let blablabla select * from tablename where blablabla; asdsad';
  result=substr(tmp,index(tmp,'select')+6);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2016 10:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301482#M63813</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-29T10:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301487#M63816</link>
      <description>&lt;PRE&gt;
How about this one:


%let text=%nrstr(%let blablabla select * from tablename where blablabla; asdsad);
%put %nrbquote(&amp;amp;text) ;

%let text2 = %qscan(%nrbquote(&amp;amp;text), 1, %str(;));
%put %nrbquote(&amp;amp;text2) ;

%let ind = %index(%qupcase(&amp;amp;text2),%str( SELECT ));
%put %nrbquote(&amp;amp;ind) ;

%let cut_text = %qsubstr(%nrbquote(&amp;amp;text2),&amp;amp;ind);
%put %nrbquote(&amp;amp;cut_text) ;



&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2016 10:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301487#M63816</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-29T10:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301489#M63817</link>
      <description>&lt;P&gt;And to satisfy your second requirement, just add a scan() call to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;s code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  tmp='%let blablabla select * from tablename where blablabla; asdsad';
  result=scan(substr(tmp,index(tmp,'select')+6),1,';');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That looks much neater than the eye-cancer-causing macro construct. And works. If you need the result in a macro variable for further use, just use call symput('cut_text',trim(result)) at the end.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 10:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301489#M63817</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-29T10:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301495#M63821</link>
      <description>&lt;P&gt;Thx to all! My problem's solved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do all text transformations in data step is a really good idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But because scan function cuts very large text (i think it has limit for one 'word'), i use substr(text, index_select, index_delim - index_select) where index_select is index of 'select' word and index_delim is index of ';'.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 11:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301495#M63821</guid>
      <dc:creator>grozzik</dc:creator>
      <dc:date>2016-09-29T11:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301504#M63824</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107359"&gt;@grozzik&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thx to all! My problem's solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do all text transformations in data step is a really good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But because scan function cuts very large text (i think it has limit for one 'word'), i use substr(text, index_select, index_delim - index_select) where index_select is index of 'select' word and index_delim is index of ';'.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As long as there is only one semicolon, scan(inval,1,';') should work, no matter how long your string is.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
length inval outval $4000;
do i = 1 to 4000;
  substr(inval,i,1) = byte(mod(i,27)+97);
  if mod(i,27) = 26 then substr(inval,i,1) = ' ';
end;
substr(inval,3995,1) = ';';
outval = scan(inval,1,';');
i = length(outval);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To create a very long string with "words" separated by blanks and 1 randomly set semicolon. i (length of outval) will come out as 3994.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 12:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301504#M63824</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-29T12:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301512#M63825</link>
      <description>&lt;P&gt;Whole my code with scan looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length text $32767;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain text '';&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile "&amp;amp;filepath" end = last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input;&lt;/P&gt;&lt;P&gt;&amp;nbsp; text = cats(text, _infile_);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ind = find(text, 'select', 'i');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; result = scan(substr(text, ind), 1, ';');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; call symput ('cut_text', result);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code doesn't work correct since scan&amp;nbsp;cuts text to ~225 symbols. I don't know why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 12:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301512#M63825</guid>
      <dc:creator>grozzik</dc:creator>
      <dc:date>2016-09-29T12:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301513#M63826</link>
      <description>&lt;P&gt;You have to include result in the length statement, or SAS will implicitly define it with the default length for scan().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Excerpt from &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm" target="_blank"&gt;Functions and Call Routines: SCAN Function&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;In a DATA step, if the SCAN function returns a value to a variable that has not yet been given a length, then that variable is given a length of 200 characters. If you need the SCAN function to assign to a variable a word that is longer than 200 characters, then you should explicitly specify the length of that variable.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 13:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301513#M63826</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-29T13:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: %scan and %nrbquote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301514#M63827</link>
      <description>&lt;P&gt;Uh oh, newbie mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx a lot! Now it works with scan too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 13:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-and-nrbquote/m-p/301514#M63827</guid>
      <dc:creator>grozzik</dc:creator>
      <dc:date>2016-09-29T13:18:57Z</dc:date>
    </item>
  </channel>
</rss>

