<?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 SAS Scanning and Output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265255#M52140</link>
    <description>&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data work.data;
length A $40;
infile datalines dsd;
Input A $;
Datalines;
uncouple between ETTX &amp;amp; TTGX
TTPX and ETTX uncoupled
separation between DTTX and
ETTX and ETTX
;
Run;

data work.blah;
set work.data;
blah = find(A,"ETTX" );
blah2 = find(A,"ETTX",blah+1);
car1 = substr(A,blah,4);
car2 = substr(A,blah2,4);
run;
&lt;/PRE&gt;
&lt;P&gt;here is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="blah4.JPG" alt="blah4.JPG" src="https://communities.sas.com/t5/image/serverpage/image-id/2862i8A4ADFE08883A5C7/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the easiest way to have SAS scan a 'list' of characters to search for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example, I not only want to search for ETTX, but DTTX, TTPX, TTGX, as well as others that aren't in this example.&amp;nbsp; is there a way for SAS to scan for the first instance of these characters and output that, and then scan again and output the second occurance?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is what i need the output to look like:&lt;/P&gt;
&lt;P&gt;&lt;IMG title="blah5.JPG" alt="blah5.JPG" src="https://communities.sas.com/t5/image/serverpage/image-id/2863i8DD20885A1CB68B8/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;and you can see the order of car1 and car2 outputs have changed too.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Apr 2016 22:07:40 GMT</pubDate>
    <dc:creator>laneylaners</dc:creator>
    <dc:date>2016-04-20T22:07:40Z</dc:date>
    <item>
      <title>SAS Scanning and Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265255#M52140</link>
      <description>&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data work.data;
length A $40;
infile datalines dsd;
Input A $;
Datalines;
uncouple between ETTX &amp;amp; TTGX
TTPX and ETTX uncoupled
separation between DTTX and
ETTX and ETTX
;
Run;

data work.blah;
set work.data;
blah = find(A,"ETTX" );
blah2 = find(A,"ETTX",blah+1);
car1 = substr(A,blah,4);
car2 = substr(A,blah2,4);
run;
&lt;/PRE&gt;
&lt;P&gt;here is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="blah4.JPG" alt="blah4.JPG" src="https://communities.sas.com/t5/image/serverpage/image-id/2862i8A4ADFE08883A5C7/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the easiest way to have SAS scan a 'list' of characters to search for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example, I not only want to search for ETTX, but DTTX, TTPX, TTGX, as well as others that aren't in this example.&amp;nbsp; is there a way for SAS to scan for the first instance of these characters and output that, and then scan again and output the second occurance?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is what i need the output to look like:&lt;/P&gt;
&lt;P&gt;&lt;IMG title="blah5.JPG" alt="blah5.JPG" src="https://communities.sas.com/t5/image/serverpage/image-id/2863i8DD20885A1CB68B8/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;and you can see the order of car1 and car2 outputs have changed too.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 22:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265255#M52140</guid>
      <dc:creator>laneylaners</dc:creator>
      <dc:date>2016-04-20T22:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Scanning and Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265258#M52141</link>
      <description>&lt;P&gt;Is there a fixed known maximum number of matches that you will find?&lt;/P&gt;
&lt;P&gt;This does the find and assign to the "car" variable. Changes would be to have the number of elements in the F array match the number of items you are going to search for, make sure the length of the F array elements is large enough (replace the 4) and have the number of items in the temporary list match the declared number.&lt;/P&gt;
&lt;P&gt;The current comparsion is on equality, you may need to UPCASE the TEMP value, the F[j] value or both for the comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.blah;
   set work.data;
   array f (5) $ 4 _temporary_ ('ETTX','TTGX','TTPX','DTTX','PPPQ');
   array result {10} $ 4 Car1-Car10;
   length temp $ 20.;
   Pos=0;
   Do i = 1 to (countw(A));
      temp = scan(a,i);
      Do j= 1 to dim(f);
         if f[j] = temp then do;
            pos = pos + 1;
            result[pos] = f[j];
         end;
      end;
   end;
   drop pos i j temp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Apr 2016 22:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265258#M52141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-20T22:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Scanning and Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265266#M52145</link>
      <description>&lt;P&gt;The easiest way is probably to switch the search around. &amp;nbsp;Take a word at a time from A, and see if it matches any of the values you are searching for ... something along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i=1 to countw(A);&lt;/P&gt;
&lt;P&gt;nextword = scan(A, i, ' ');&lt;/P&gt;
&lt;P&gt;if nextword in ('ETTX', 'DTTX', etc.) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 22:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265266#M52145</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-20T22:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Scanning and Output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265277#M52149</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
length A $40;
infile datalines dsd;
Input A $;
Datalines;
uncouple between ETTX &amp;amp; TTGX
TTPX and ETTX uncoupled
separation between DTTX and
ETTX and ETTX
;
Run;
data want;
 set have;
 pid=prxparse('/ETTX|TTGX|TTPX|DTTX/o');
 s=1;
 e=length(a);
 call prxnext(pid,s,e,a,p,l);
 do while(p&amp;gt;0);
  found=substr(a,p,l);
  output;
  call prxnext(pid,s,e,a,p,l);
 end;
 drop s e p l pid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 01:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Scanning-and-Output/m-p/265277#M52149</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-21T01:28:51Z</dc:date>
    </item>
  </channel>
</rss>

