<?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: CHARACTER CONTAINS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449928#M113293</link>
    <description>&lt;P&gt;Your do loop is bringing you multiple outputs. Just use INDEX or FIND or PRXMATCH function to find a specific character in your string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if prxmatch("m/X|Y|Z/oi",DAT) then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if find(dat,'X') or find(dat,'Y') or find(dat,'Z') then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if index(dat,'X') or index(dat,'Y') or index(dat,'Z') then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Mar 2018 13:42:43 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-03-30T13:42:43Z</dc:date>
    <item>
      <title>CHARACTER CONTAINS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449917#M113289</link>
      <description>&lt;P&gt;*33.I have a variable with the name of TAN_NUMBER and below are the values:&lt;BR /&gt;Write a program to create a new variable DESTINATION when X,Y,Z encounters the&lt;BR /&gt;value should be INTERNATIONAL otherwise DOMESTIC.;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;&lt;BR /&gt;DATA GIVEN;&lt;BR /&gt;INPUT DAT$ @@;&lt;BR /&gt;DO I=1 TO LENGTH(DAT);&lt;BR /&gt;IF SUBSTR(DAT,I,1) IN ('X','Y','Z') THEN DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';OUTPUT;END;&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;RUN;&lt;/P&gt;&lt;P&gt;I WILL GET MULTIPLE OUPUT IF&amp;nbsp; X OR Y OR Z CONTAINS DESTI='INTER'&lt;/P&gt;&lt;P&gt;ELSE 'DOMESTIC'&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 13:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449917#M113289</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2018-03-30T13:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: CHARACTER CONTAINS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449928#M113293</link>
      <description>&lt;P&gt;Your do loop is bringing you multiple outputs. Just use INDEX or FIND or PRXMATCH function to find a specific character in your string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if prxmatch("m/X|Y|Z/oi",DAT) then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if find(dat,'X') or find(dat,'Y') or find(dat,'Z') then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;DATA GIVEN;&lt;BR /&gt;infile datalines;&lt;BR /&gt;INPUT DAT $ 1-50;&lt;BR /&gt;if index(dat,'X') or index(dat,'Y') or index(dat,'Z') then DESTINATION='INTERNATIONAL';&lt;BR /&gt;ELSE DESTINATION='DOMESTIC';&lt;BR /&gt;DATALINES;&lt;BR /&gt;T123 TY333 1357Z UZYX 888 ABC&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Mar 2018 13:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449928#M113293</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-30T13:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: CHARACTER CONTAINS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449933#M113296</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA GIVEN;
INPUT DAT$ @@;
if FINDC(DAT,'XYZ') THEN DESTINATION='INTERNATIONAL';
ELSE DESTINATION='DOMESTIC';
DATALINES;
T123 TY333 1357Z UZYX 888 ABC
;RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Mar 2018 14:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/449933#M113296</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2018-03-30T14:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: CHARACTER CONTAINS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/450130#M113335</link>
      <description>&lt;P&gt;This is the wrong approach for this problem as there is a function, INDEXC(), that does what you need already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the reason you are getting multiple outputs is a logic problem with how you structured your DO loop.&amp;nbsp; You should not have an OUTPUT statement in the loop.&amp;nbsp; Instead you should use the loop to set the value.&amp;nbsp; Typically you set the initial value and then when you find a match change the value.&amp;nbsp; Note that DO statement allows you to have both an iterative part and a other parts.&amp;nbsp; So you can stop searching once you have found changed the destination value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could construct your DESTINATION variable like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length destination $15;
destination='DOMESTIC';
do I=1 to length(dat) while (destination='DOMESTIC');
  if substr(dat,I,1) in ('X','Y','Z') then destination='INTERNATIONAL';
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Mar 2018 13:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CHARACTER-CONTAINS/m-p/450130#M113335</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-31T13:40:46Z</dc:date>
    </item>
  </channel>
</rss>

