<?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: do - end structure and if structure interaction in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575608#M162858</link>
    <description>&lt;P&gt;I don't know SPSS syntax but your code looks like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array x{10};
do i = 1 to dim(x);
    if z = 12 then x{i} = x{i} + 2;
    else if z = 15 then x{i} = x{i} + 5;
    else x{i} = x{i} + 15;
    end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 22 Jul 2019 22:00:29 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-07-22T22:00:29Z</dc:date>
    <item>
      <title>do - end structure and if structure interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575600#M162851</link>
      <description>&lt;P&gt;Again, i want to emphasize i come from spss and i'm very new to sas. I'm looking for sas equivalents.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's some spss code.&lt;/P&gt;&lt;P&gt;vector xvec=x1 to x10. * same as array xvec{10} x1-x10;&lt;/P&gt;&lt;P&gt;loop i=1 to 10; * same as do i=1 to 10;&lt;/P&gt;&lt;P&gt;do if (z eq 12).&lt;/P&gt;&lt;P&gt;compute x(i)=x(i)+2.&lt;/P&gt;&lt;P&gt;else if (z eq 15).&lt;/P&gt;&lt;P&gt;compute x(i)=x(i)+5.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;compute x(i)=x(i)+15.&lt;/P&gt;&lt;P&gt;end if.&lt;/P&gt;&lt;P&gt;end loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An alternative (with a variation) would-could be&lt;/P&gt;&lt;P&gt;vector xvec=x1 to x10.&amp;nbsp;&lt;/P&gt;&lt;P&gt;do if (z eq 12).&lt;/P&gt;&lt;P&gt;loop i=1 to 10;&amp;nbsp;&lt;/P&gt;&lt;P&gt;compute x(i)=x(i)+2.&lt;/P&gt;&lt;P&gt;end loop.&lt;/P&gt;&lt;P&gt;else if (z eq 15).&lt;/P&gt;&lt;P&gt;loop i=1 to 10;&amp;nbsp;&lt;/P&gt;&lt;P&gt;compute x(i)=x(i)+15.&lt;/P&gt;&lt;P&gt;end loop.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;compute w=x1*x3.&lt;/P&gt;&lt;P&gt;end if.&lt;/P&gt;&lt;P&gt;end loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know (courtesy of Ron Cody's book) that sas has a if-else if structure but&amp;nbsp; my (very limited) understanding is that if-else if can't interact with a do-end structure because the if-else if must have a 'then' result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume sas can do this; but how?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, Gene Maguin&lt;/P&gt;&lt;P&gt;PS. I'm interested in suggestions of sas books that build on Ron's book.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 21:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575600#M162851</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2019-07-22T21:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: do - end structure and if structure interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575608#M162858</link>
      <description>&lt;P&gt;I don't know SPSS syntax but your code looks like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array x{10};
do i = 1 to dim(x);
    if z = 12 then x{i} = x{i} + 2;
    else if z = 15 then x{i} = x{i} + 5;
    else x{i} = x{i} + 15;
    end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 22:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575608#M162858</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-07-22T22:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: do - end structure and if structure interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575613#M162862</link>
      <description>&lt;P&gt;If I remember the SPSS correctly then&lt;/P&gt;
&lt;PRE&gt;vector xvec=x1 to x10. 
do if (z eq 12).
loop i=1 to 10; 
compute x(i)=x(i)+2.
end loop.
else if (z eq 15).
loop i=1 to 10; 
compute x(i)=x(i)+15.
end loop.
else.
compute w=x1*x3.
end if.
end loop.
 
would be:

array x{10};
if z = 12 then do i = 1 to dim(x);
   x{i} = x{i} + 2;
end;
else if z = 15 then do i = 1 to dim(x);
   x{i} = x{i} + 5;
end;
else  w=x1*x3;&lt;/PRE&gt;
&lt;P&gt;You could use the same approach that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;with&amp;nbsp; the W=x1*x3 calculation instead of the x{I}=x{I}+15&amp;nbsp;, it would just be done 10 times with identical results.&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;select (z);
   when (12) do i = 1 to dim(x);
               x{i} = x{i} + 2;
            end;
   when (15) do i = 1 to dim(x);
               x{i} = x{i} + 5;
            end;
   otherwise w=x1*x3;
end;&lt;/PRE&gt;
&lt;P&gt;The select statement/when/block becomes more attractive when there are more than 2 or 3 "elses" involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And sometimes you get semi-slick values and&lt;/P&gt;
&lt;PRE&gt;if z in (12 15) then do i= 1 to dim(x);
   x[i] = x[i] + (z-10);
end;
else  w=x1*x3;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 23:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575613#M162862</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-22T23:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: do - end structure and if structure interaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575628#M162875</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;loop i=1 to 10; * same as do i=1 to 10;&lt;/P&gt;
&lt;P&gt;do if (z eq 12).&lt;/P&gt;
&lt;P&gt;compute x(i)=x(i)+2.&lt;/P&gt;
&lt;P&gt;else if (z eq 15).&lt;/P&gt;
&lt;P&gt;compute x(i)=x(i)+5.&lt;/P&gt;
&lt;P&gt;else.&lt;/P&gt;
&lt;P&gt;compute x(i)=x(i)+15.&lt;/P&gt;
&lt;P&gt;end if.&lt;/P&gt;
&lt;P&gt;end loop.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Another way::&lt;/P&gt;
&lt;PRE&gt;do I= 1 to dim(X);
   X[I] = X[I] + 2*(Z=12) + 5*(Z=15) + 15*(Z ^in (12 15));
end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 02:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-end-structure-and-if-structure-interaction/m-p/575628#M162875</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-23T02:59:45Z</dc:date>
    </item>
  </channel>
</rss>

