<?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: The most efficient way to carry out several statements at once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457873#M116146</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=basess&amp;amp;docsetTarget=p0pcj5ajwyngron1wlsq0tet0hce.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=basess&amp;amp;docsetTarget=p0pcj5ajwyngron1wlsq0tet0hce.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="xis-code"&gt;   /* a more efficient method */
data updatedattractions2;
   set mylib.attractions;
   &lt;SPAN class="xis-codeFocus"&gt;if City = 'Madrid' then&lt;/SPAN&gt;
      &lt;SPAN class="xis-codeFocus"&gt;do;&lt;/SPAN&gt;
         &lt;SPAN class="xis-codeFocus"&gt;Museums = 3;&lt;/SPAN&gt;
         &lt;SPAN class="xis-codeFocus"&gt;Other = 2;&lt;/SPAN&gt;
      &lt;SPAN class="xis-codeFocus"&gt;end;&lt;/SPAN&gt;
&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Apr 2018 18:42:31 GMT</pubDate>
    <dc:creator>HB</dc:creator>
    <dc:date>2018-04-26T18:42:31Z</dc:date>
    <item>
      <title>The most efficient way to carry out several statements at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457866#M116144</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to SAS, although I am learning. My only prior programming experience was with Tradestation Easy Language which, is, way more intuitive than SAS. Here, I am looking to run several statements at once. In Tradestation, it would run something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If Condition 1 then begin ;&lt;/P&gt;&lt;P&gt;Variable1 = X&lt;/P&gt;&lt;P&gt;Variable2 = Y&lt;/P&gt;&lt;P&gt;Variable3 = Z ;&lt;/P&gt;&lt;P&gt;...Variable1000 = ZZ ;&amp;nbsp;&amp;nbsp; (ETC.)&lt;/P&gt;&lt;P&gt;End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok... now in SAS, I want to do something similar. I have looked at arrays, and maybe that is the best way here, or not.&lt;/P&gt;&lt;P&gt;Below is the code. Now, if I had 100 different arguments or variables etc, which would be calculated if condition 1 were true, what is the most efficient way to write this code? Here, the condition is Nmiss(of Score1-Score5) eq 0. How can I only write this condition once and have the Maxscore, SecondLargest, and Minscore calculated?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data review.Evaluate ; 
	Set learn.psych ; 
	If Nmiss(of Score1-Score5) eq 0 then Maxscore = Max(of Score1-score5) ; 
	If Nmiss(of Score1-Score5) eq 0 then SecondLargest = Largest(2, of Score1-score5) ;
	If Nmiss(of Score1-Score5) eq 0 then Minscore = Min(of Score1-Score5) ; 
run ; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 18:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457866#M116144</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-04-26T18:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: The most efficient way to carry out several statements at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457873#M116146</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=basess&amp;amp;docsetTarget=p0pcj5ajwyngron1wlsq0tet0hce.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=basess&amp;amp;docsetTarget=p0pcj5ajwyngron1wlsq0tet0hce.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="xis-code"&gt;   /* a more efficient method */
data updatedattractions2;
   set mylib.attractions;
   &lt;SPAN class="xis-codeFocus"&gt;if City = 'Madrid' then&lt;/SPAN&gt;
      &lt;SPAN class="xis-codeFocus"&gt;do;&lt;/SPAN&gt;
         &lt;SPAN class="xis-codeFocus"&gt;Museums = 3;&lt;/SPAN&gt;
         &lt;SPAN class="xis-codeFocus"&gt;Other = 2;&lt;/SPAN&gt;
      &lt;SPAN class="xis-codeFocus"&gt;end;&lt;/SPAN&gt;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 18:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457873#M116146</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-04-26T18:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: The most efficient way to carry out several statements at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457878#M116149</link>
      <description>&lt;P&gt;Ok. So loop, without arrays, seems to be the most efficient in this case. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 18:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457878#M116149</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-04-26T18:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: The most efficient way to carry out several statements at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457929#M116170</link>
      <description>&lt;P&gt;Mostly to have an answer for others in the future with a similar question an example based directly on the question code:&lt;/P&gt;
&lt;PRE&gt;Data review.Evaluate ; 
   Set learn.psych ; 
   If Nmiss(of Score1-Score5) eq 0 then do;
      Maxscore = Max(of Score1-score5) ; 
      SecondLargest = Largest(2, of Score1-score5) ;
      Minscore = Min(of Score1-Score5) ; 
   end;
run ; &lt;/PRE&gt;
&lt;P&gt;Which is an example of "factoring out the common code", the Nmiss condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have different blocks of code based on how many were missing you could use the Select block such as:&lt;/P&gt;
&lt;PRE&gt;Data review.Evaluate ; 
   Set learn.psych ; 
   select (Nmiss(of Score1-Score5));
      when (0) do; &amp;lt;some block of code&amp;gt;; end;
      when (1,2,3) do; &amp;lt;some other block of code&amp;gt;; end;
      when (4,5) do; &amp;lt;some different block of code&amp;gt;; end;
      otherwise do; &amp;lt;something or nothing&amp;gt;;end;
   end;&lt;/PRE&gt;
&lt;P&gt;Which evaluates the Nmiss(of Score1-Score5) and branches to the appropriate number value indicated in the WHEN clauses within the ().&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 19:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-most-efficient-way-to-carry-out-several-statements-at-once/m-p/457929#M116170</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-26T19:52:00Z</dc:date>
    </item>
  </channel>
</rss>

