<?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: how to subset a dataset based on if a range of variables contain specific values? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426984#M68400</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175222"&gt;@Viveme789&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;Suppose I have a dataset looks like the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ID .&amp;nbsp; &amp;nbsp; &amp;nbsp;age&amp;nbsp; MED1&amp;nbsp; &amp;nbsp; MED2&amp;nbsp; &amp;nbsp; MED3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;001 .&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1055&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7832&amp;nbsp; &amp;nbsp; 3435&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;202 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1051&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3423&amp;nbsp; &amp;nbsp; 3455&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;204 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 5040&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3423 .&amp;nbsp; 3444&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;213 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;9999&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3432 .&amp;nbsp; 4546&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each patient has three prescriptions and each has a code comes with it. I want to see if patients age less than 5 have prescription MED1-MED3 in code (7832, 3435, 1051).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used proc sql the following but it gave me the same dataset.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WANT AS
		SELECT *
		FROM MEDS
                WHERE MED1 OR MED2 OR MED3 IN (7832, 3455, 1051) AND&lt;BR /&gt;                  AGE &amp;lt;= 5;&lt;BR /&gt;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I correct this? Thanks.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL doesn't do variable lists or multiple variables well, it would be easier in a data step, otherwise you need to duplicate your condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE MED1  IN (7832, 3455, 1051) 
OR MED2  IN (7832, 3455, 1051)
OR MED3 IN (7832, 3455, 1051) ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Jan 2018 20:03:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-01-11T20:03:38Z</dc:date>
    <item>
      <title>how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426982#M68398</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Suppose I have a dataset looks like the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID .&amp;nbsp; &amp;nbsp; &amp;nbsp;age&amp;nbsp; MED1&amp;nbsp; &amp;nbsp; MED2&amp;nbsp; &amp;nbsp; MED3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;001 .&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1055&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7832&amp;nbsp; &amp;nbsp; 3435&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;202 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1051&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3423&amp;nbsp; &amp;nbsp; 3455&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;204 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 5040&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3423 .&amp;nbsp; 3444&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;213 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;9999&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3432 .&amp;nbsp; 4546&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each patient has three prescriptions and each has a code comes with it. I want to see if patients age less than 5 have prescription MED1-MED3 in code (7832, 3435, 1051).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used proc sql the following but it gave me the same dataset.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WANT AS
		SELECT *
		FROM MEDS
                WHERE MED1 OR MED2 OR MED3 IN (7832, 3455, 1051) AND&lt;BR /&gt;                  AGE &amp;lt;= 5;&lt;BR /&gt;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I correct this? Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 19:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426982#M68398</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2018-01-11T19:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426983#M68399</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;&lt;BR /&gt;/* if i understand you correctly*/&lt;BR /&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;SQL&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	CREATE &lt;SPAN class="token statement"&gt;TABLE&lt;/SPAN&gt; WANT AS
		&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;
		&lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; MEDS
                &lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; MED1=7832 and MED2=3455 and MED3=1051 AND   AGE &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;5&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;QUIT&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426983#M68399</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-11T20:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426984#M68400</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175222"&gt;@Viveme789&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;Suppose I have a dataset looks like the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ID .&amp;nbsp; &amp;nbsp; &amp;nbsp;age&amp;nbsp; MED1&amp;nbsp; &amp;nbsp; MED2&amp;nbsp; &amp;nbsp; MED3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;001 .&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1055&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7832&amp;nbsp; &amp;nbsp; 3435&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;202 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1051&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3423&amp;nbsp; &amp;nbsp; 3455&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;204 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 5040&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3423 .&amp;nbsp; 3444&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;213 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;9999&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3432 .&amp;nbsp; 4546&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each patient has three prescriptions and each has a code comes with it. I want to see if patients age less than 5 have prescription MED1-MED3 in code (7832, 3435, 1051).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used proc sql the following but it gave me the same dataset.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WANT AS
		SELECT *
		FROM MEDS
                WHERE MED1 OR MED2 OR MED3 IN (7832, 3455, 1051) AND&lt;BR /&gt;                  AGE &amp;lt;= 5;&lt;BR /&gt;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I correct this? Thanks.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL doesn't do variable lists or multiple variables well, it would be easier in a data step, otherwise you need to duplicate your condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE MED1  IN (7832, 3455, 1051) 
OR MED2  IN (7832, 3455, 1051)
OR MED3 IN (7832, 3455, 1051) ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426984#M68400</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-11T20:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426985#M68401</link>
      <description>&lt;P&gt;I meant as if MED1, MED2 and MED3 has the values in the list.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426985#M68401</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2018-01-11T20:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426987#M68402</link>
      <description>&lt;P&gt;Can you tell me how to do it in a data step, where I don't have to duplicate the list of values? The problem I have on hand actually have 98 codes in the list and 9 variables.... Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/426987#M68402</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2018-01-11T20:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427035#M68414</link>
      <description>&lt;P&gt;How is your list of 98 codes stored?&amp;nbsp; Can it be a SAS data set with 98 observations and a single variable?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 21:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427035#M68414</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-11T21:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427036#M68415</link>
      <description>&lt;P&gt;I meant that 9 variables MED1 to MED9 has to have values that contains in the list, which has 98 codes as a criteria to subset the data. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;MED1 OR MED2 OR...OR MED9&amp;nbsp;IN (1, 2, ....98). Do I make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 21:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427036#M68415</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2018-01-11T21:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427038#M68417</link>
      <description>&lt;P&gt;100%.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But my question remains the same.&amp;nbsp; Can you put the list of 98 possible values into a SAS data set that contains 98 observations and 1 variable?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 21:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427038#M68417</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-11T21:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427041#M68419</link>
      <description>&lt;P&gt;Yes&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 22:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427041#M68419</guid>
      <dc:creator>Viveme789</dc:creator>
      <dc:date>2018-01-11T22:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to subset a dataset based on if a range of variables contain specific values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427097#M68423</link>
      <description>&lt;P&gt;OK, assuming you have a separate SAS data set with 98 observations, and just one variable (MED):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set _98_meds;&lt;/P&gt;
&lt;P&gt;start=med;&lt;/P&gt;
&lt;P&gt;end='In the List';&lt;/P&gt;
&lt;P&gt;fmtname='_my98_';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc format cntlin=temp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This much gives you a format that translates any of the 98 meds into "In the List".&amp;nbsp; Then use that format to compare to the 9 meds (MED1 through MED9):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;where age &amp;lt;= 5;&lt;/P&gt;
&lt;P&gt;array med {9};&lt;/P&gt;
&lt;P&gt;do _n_=1 to 9 until (flag='In the List');&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;flag = put(med{_n_}, _my98_.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if flag='In the List';&lt;/P&gt;
&lt;P&gt;drop flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 03:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-subset-a-dataset-based-on-if-a-range-of-variables-contain/m-p/427097#M68423</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-12T03:51:27Z</dc:date>
    </item>
  </channel>
</rss>

