<?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 Using the IN Statement w/ a Continuous Variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855638#M37702</link>
    <description>&lt;P&gt;Is there a way to use the IN statement w/ a continuous variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With categorical variables, I often subset using the WHERE and IN statements:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;:&amp;nbsp;WHERE race IN(2,3,4);&lt;/P&gt;
&lt;P&gt;In this scenario, the variable "race" is categorical/nominal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Is there a way to do this with a continuous variable, like age?&amp;nbsp;Age: 0-59&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you input the values you desire within the parentheses?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;: WHERE age IN(0:18); or&amp;nbsp;WHERE age IN(0:&amp;lt;19)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or can you use a format?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;: WHERE age IN("&amp;nbsp;≤ 18 YOA");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Format
Value&amp;nbsp;
age_fmt
0 - 18 = "&amp;nbsp;≤ 18 YOA"
19 - 35 = "19 to 25 YOA"
36 to High = "&amp;gt; 35";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2023 20:17:08 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2023-01-25T20:17:08Z</dc:date>
    <item>
      <title>Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855638#M37702</link>
      <description>&lt;P&gt;Is there a way to use the IN statement w/ a continuous variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With categorical variables, I often subset using the WHERE and IN statements:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;:&amp;nbsp;WHERE race IN(2,3,4);&lt;/P&gt;
&lt;P&gt;In this scenario, the variable "race" is categorical/nominal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Is there a way to do this with a continuous variable, like age?&amp;nbsp;Age: 0-59&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you input the values you desire within the parentheses?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;: WHERE age IN(0:18); or&amp;nbsp;WHERE age IN(0:&amp;lt;19)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or can you use a format?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;: WHERE age IN("&amp;nbsp;≤ 18 YOA");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Format
Value&amp;nbsp;
age_fmt
0 - 18 = "&amp;nbsp;≤ 18 YOA"
19 - 35 = "19 to 25 YOA"
36 to High = "&amp;gt; 35";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 20:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855638#M37702</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2023-01-25T20:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855641#M37703</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Can you input the values you desire within the parentheses?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;: WHERE age IN(0:18); or&amp;nbsp;WHERE age IN(0:&amp;lt;19)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer is very simple. Try it and see. (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 4&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Is there a way to do this with a continuous variable, like age?&amp;nbsp;Age: 0-59&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More generally, you can use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where age&amp;lt;=59;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or if there is a lower limit&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where 12 &amp;lt;= age &amp;lt;=59;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 20:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855641#M37703</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-25T20:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855654#M37706</link>
      <description>&lt;P&gt;Is your variable truly continuous or a range of INTEGER values?&lt;/P&gt;
&lt;P&gt;If your values are &lt;STRONG&gt;integers&lt;/STRONG&gt; you can use in (0:18) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you compare a numeric variable to a formatted value you better apply the format to the variable such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if put(age,age_fmt.) in ('&amp;lt;the formatted value&amp;gt;')&lt;/PRE&gt;
&lt;P&gt;otherwise you are comparing a number to text and SAS will attempt to turn one of them into the proper type for the comparison and you will get 1) conversion notes in the log and very likely 2) missing values as they aren't compatible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 21:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855654#M37706</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-25T21:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855675#M37711</link>
      <description>&lt;P&gt;Good point about a numeric variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a little confused by "if put(age,age_fmt.)..."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Will the "in ('&amp;lt;the formatted value&amp;gt;')" work for a numeric variable, independent of the "if put(age,age_fmt.)"?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;WHERE age IN(" ≤ 18 YOA");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming age is numeric (e.g., 21.3 years)&amp;nbsp;and the format " ≤ 18 YOA".&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2023 02:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855675#M37711</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2023-01-26T02:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855677#M37712</link>
      <description>&lt;P&gt;No. If you are using a formatted value comparison you have to apply the format using the PUT function. If you use just a value comparison, you use the actual numeric values stored.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2023 03:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855677#M37712</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-26T03:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IN Statement w/ a Continuous Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855678#M37713</link>
      <description>&lt;P&gt;You cannot compare a NUMBER, the actual value of the variable AGE, with a STRING, the text generated by the format attached to the variable AGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you don't have to use PUT().&amp;nbsp; If the format is attached to the variable you can use VVALUE() instead.&amp;nbsp; But then you cannot use a WHERE statement.&amp;nbsp; So use IF instead.&lt;/P&gt;
&lt;PRE&gt;    1  data test;
    2   set sashelp.class;
    3   where age = 13;
    4  run;

NOTE: There were 3 observations read from the data set SASHELP.CLASS.
      WHERE age=13;
NOTE: The data set WORK.TEST has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


    5  data test;
    6   set sashelp.class;
    7   if left(vvalue(age)) = '13';
    8  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2023 03:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-IN-Statement-w-a-Continuous-Variable/m-p/855678#M37713</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-26T03:37:06Z</dc:date>
    </item>
  </channel>
</rss>

