<?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: Using the select statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762359#M39356</link>
    <description>&lt;P&gt;When you use %include you're telling SAS to bring in the contents of that file as lines of code -- directly into the location where you used the %include statement. Those lines of code must be syntactically correct and appropriate for running there&amp;nbsp;&lt;STRONG&gt;as if&lt;/STRONG&gt; they were embedded directly in the program you're running.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So a&amp;nbsp;&lt;STRONG&gt;select...when&lt;/STRONG&gt; clause is valid within a DATA step. Your Select2.sas example includes the DATA step statements, which would in effect embed DATA step statements&amp;nbsp;&lt;EM&gt;inside&lt;/EM&gt; another DATA step...which doesn't make sense and could cause the errors.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Aug 2021 18:25:28 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2021-08-18T18:25:28Z</dc:date>
    <item>
      <title>Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762327#M39350</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to modify a sas program which is called with an include statement.&lt;/P&gt;
&lt;P&gt;Anyway!&lt;/P&gt;
&lt;P&gt;Here's a little piece of the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when( vehicle_cd in ('AA', 'PP') type3=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; otherwise type3=2;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I bring this code into SAS EG, the select , otherwise and end are in red.&lt;/P&gt;
&lt;P&gt;I wonder how this code is working properly.&amp;nbsp; Will it be a best practice to modify the code as below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;/P&gt;
&lt;P&gt;Select;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when( vehicle_cd in ('AA', 'PP') type3=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; otherwise type3=2;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 16:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762327#M39350</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-18T16:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using the selecf statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762328#M39351</link>
      <description>&lt;P&gt;You are talking about what the code looks like in the EDITOR?&amp;nbsp; The editor is not the SAS language, it is just a tool for editing the text that has your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the SAS log say when you actually send the code to SAS to run?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 16:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762328#M39351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-18T16:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using the selecf statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762343#M39352</link>
      <description>Your code has syntax errors - missing brackets for starters so it should be red. SAS can correct some of this - and this will be noted in the log. &lt;BR /&gt;Your example isn't realistic so I'm not sure what you're asking since it's not valid code.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Aug 2021 16:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762343#M39352</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-18T16:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using the selecf statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762350#M39353</link>
      <description>&lt;P&gt;The editor in PC-SAS does a pretty good job of detecting the syntax with that code. Even without the missing right parenthesis.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62704iD67C2A4468F05CED/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But if the DATA statement is not there the SELECT is in red since you cannot use it outside of a data step.&lt;/P&gt;
&lt;P&gt;So perhaps the line before the DATA statement is the issue. For example it might be missing a closing semi-colon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 449px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62705i30A4C9D905E6BE65/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 17:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762350#M39353</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-18T17:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762351#M39354</link>
      <description>&lt;P&gt;For more about the SELECT statement in DATA step, &lt;A href="https://blogs.sas.com/content/iml/2016/06/20/select-when-sas-data-step.html" target="_self"&gt;I recommend this blog post&lt;/A&gt; from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/* example of using the SELECT statement */
data Heart / view=Heart;
set sashelp.heart;
select (Smoking_Status);
   when ('Non-smoker')        Smoking_Cat=1;
   when ('Light (1-5)')       Smoking_Cat=2;
   when ('Moderate (6-15)')   Smoking_Cat=3;
   when ('Heavy (16-25)')     Smoking_Cat=4;
   when ('Very Heavy (&amp;gt; 25)') Smoking_Cat=5;
   otherwise                  Smoking_Cat=.;
end;
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 17:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762351#M39354</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-08-18T17:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762358#M39355</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;based on your nice example, I have perfom three tests.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One with your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;another one with the use of the&amp;nbsp; select1.sas&lt;/P&gt;
&lt;P&gt;select (Smoking_Status);&lt;BR /&gt;when ('Non-smoker') Smoking_Cat=1;&lt;BR /&gt;when ('Light (1-5)') Smoking_Cat=2;&lt;BR /&gt;when ('Moderate (6-15)') Smoking_Cat=3;&lt;BR /&gt;when ('Heavy (16-25)') Smoking_Cat=4;&lt;BR /&gt;when ('Very Heavy (&amp;gt; 25)') Smoking_Cat=5;&lt;BR /&gt;otherwise Smoking_Cat=.;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;another with the select2.sas&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;BR /&gt;select (Smoking_Status);&lt;BR /&gt;when ('Non-smoker') Smoking_Cat=1;&lt;BR /&gt;when ('Light (1-5)') Smoking_Cat=2;&lt;BR /&gt;when ('Moderate (6-15)') Smoking_Cat=3;&lt;BR /&gt;when ('Heavy (16-25)') Smoking_Cat=4;&lt;BR /&gt;when ('Very Heavy (&amp;gt; 25)') Smoking_Cat=5;&lt;BR /&gt;otherwise Smoking_Cat=.;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;****&lt;/P&gt;
&lt;P&gt;Then I have executed the two programs below .&amp;nbsp; I have noticed no difference.&lt;/P&gt;
&lt;P&gt;The only this is with the select2.sas, the fact that I have put my code between data _null_; and run;&lt;/P&gt;
&lt;P&gt;make the red codes to desapear&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* example of using the SELECT statement */&lt;BR /&gt;data Heart / view=Heart;&lt;BR /&gt;set sashelp.heart;&lt;BR /&gt;%include "/SAS Snippets/select1.sas";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/* example of using the SELECT statement */&lt;BR /&gt;data Heart / view=Heart;&lt;BR /&gt;set sashelp.heart;&lt;BR /&gt;%include "/SAS Snippets/select2.sas";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 18:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762358#M39355</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-18T18:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762359#M39356</link>
      <description>&lt;P&gt;When you use %include you're telling SAS to bring in the contents of that file as lines of code -- directly into the location where you used the %include statement. Those lines of code must be syntactically correct and appropriate for running there&amp;nbsp;&lt;STRONG&gt;as if&lt;/STRONG&gt; they were embedded directly in the program you're running.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So a&amp;nbsp;&lt;STRONG&gt;select...when&lt;/STRONG&gt; clause is valid within a DATA step. Your Select2.sas example includes the DATA step statements, which would in effect embed DATA step statements&amp;nbsp;&lt;EM&gt;inside&lt;/EM&gt; another DATA step...which doesn't make sense and could cause the errors.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 18:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762359#M39356</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-08-18T18:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762372#M39358</link>
      <description>&lt;P&gt;Please re-read my first response. The color coding of the editor has nothing to do with whether or not you have created valid code.&amp;nbsp; Ignore it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no way that the SAS program editor &lt;STRONG&gt;can read your mind&lt;/STRONG&gt; to know that your intent is in the future to use %INCLUDE to use this snippet of code to build a data step.&amp;nbsp; So without the full data step in the editor window at the same time there is no way that the editor can know that SELECT is being used properly or not.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 20:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762372#M39358</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-18T20:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762382#M39359</link>
      <description>Your SELECT 1 is correct, your SELECT2 is incorrect but IMO I would use a format and not do it this way though it's technically possible.....</description>
      <pubDate>Wed, 18 Aug 2021 21:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762382#M39359</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-18T21:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using the select statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762701#M39375</link>
      <description>&lt;P&gt;you are right.&amp;nbsp; I did some test today using data _null_; ... run; and it failed.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 21:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-the-select-statement/m-p/762701#M39375</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-19T21:27:54Z</dc:date>
    </item>
  </channel>
</rss>

