<?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 Scan with if and else statement SAS9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592781#M169998</link>
    <description>&lt;P&gt;HI I am trying to use the scan function .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i am trying to do is to if address 1 contains the apt number flip and change address 1 and address 2. if it doesnt keep the same values. But the code for some reason is assigning only the first character to the variable a1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example if address1= 123 main st&amp;nbsp; a1= 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but if i flip the if and else statements it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example if address1= 123 main st&amp;nbsp; a1= 123 main st.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not understand why is this happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same logic works on a diff data set.&amp;nbsp; The current address data is being imported from a excel file.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data_1;
set data _2;

if SCAN(address1,1,' ') in
('APT',) then do;
a1 = Address2;
a2 = Address1;
switch=1;
end;

else if  SCAN(address1,1,' ') not in
('APT',) then do;
a1 = Address1;
a2 = Address2;
switch=1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Sep 2019 18:10:55 GMT</pubDate>
    <dc:creator>vjm</dc:creator>
    <dc:date>2019-09-30T18:10:55Z</dc:date>
    <item>
      <title>Scan with if and else statement SAS9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592781#M169998</link>
      <description>&lt;P&gt;HI I am trying to use the scan function .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i am trying to do is to if address 1 contains the apt number flip and change address 1 and address 2. if it doesnt keep the same values. But the code for some reason is assigning only the first character to the variable a1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example if address1= 123 main st&amp;nbsp; a1= 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but if i flip the if and else statements it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example if address1= 123 main st&amp;nbsp; a1= 123 main st.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not understand why is this happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same logic works on a diff data set.&amp;nbsp; The current address data is being imported from a excel file.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data_1;
set data _2;

if SCAN(address1,1,' ') in
('APT',) then do;
a1 = Address2;
a2 = Address1;
switch=1;
end;

else if  SCAN(address1,1,' ') not in
('APT',) then do;
a1 = Address1;
a2 = Address2;
switch=1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 18:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592781#M169998</guid>
      <dc:creator>vjm</dc:creator>
      <dc:date>2019-09-30T18:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Scan with if and else statement SAS9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592786#M170001</link>
      <description>&lt;P&gt;Not sure why you attached a FILE to show three lines of text.&lt;/P&gt;
&lt;PRE&gt;209 SW KESTOR DR
14638 TROPICAL DR
7082 CEDARHURST DR&lt;/PRE&gt;
&lt;P&gt;None of those lines contain the text string APT.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 18:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592786#M170001</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-30T18:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Scan with if and else statement SAS9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592812#M170015</link>
      <description>&lt;P&gt;Try posting data as a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure that the posted data has examples of both sorts of values. Your CSV didn't have any APT or records with Address2 values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, this has several errors.&lt;/P&gt;
&lt;PRE&gt;data_1;
set data _2;
&lt;/PRE&gt;
&lt;P&gt;a data step starts with the keyword DATA and if you want to name the date set place it after the key word:&lt;/P&gt;
&lt;P&gt;Data _1;&lt;/P&gt;
&lt;P&gt;However the SET statement just takes the name of the data set.&lt;/P&gt;
&lt;P&gt;So you either want&lt;/P&gt;
&lt;PRE&gt;data _1;
set _2;
&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;data _1;
set data_2;
&lt;/PRE&gt;
&lt;P&gt;Though I would typically expect the lower numbered of series of data sets on the SET statement.&lt;/P&gt;
&lt;P&gt;When you get unexpected results it is also a good idea to copy the log with the code and any messages and paste that to a code box.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 19:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592812#M170015</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-30T19:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Scan with if and else statement SAS9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592897#M170065</link>
      <description>&lt;P&gt;1. The code you supplied is invalid.&lt;/P&gt;
&lt;P&gt;2. You logic can be simplified to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if ADDRESS1 =: 'APT ' then do;
    A1 = ADDRESS2;
    A2 = ADDRESS1;
    SWITCH=1;
  end;
  else do;
    A1 = ADDRESS1;
    A2 = ADDRESS2;
    SWITCH=1;
  end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;provided ADDRESS1 is left-aligned.&lt;/P&gt;
&lt;P&gt;3. Note that variable SWITCH is always set to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 03:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-with-if-and-else-statement-SAS9-4/m-p/592897#M170065</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-01T03:25:28Z</dc:date>
    </item>
  </channel>
</rss>

