<?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 How do I subset a dataset using a range of conditions that contains &amp;quot;at least&amp;quot;? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619185#M19344</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First time user and still a newbie at SAS. I'm working on just basic descriptives on a dataset that contains 50+ variables with&amp;nbsp; age in months (ageinmonths) as a variable ranging from 1 months to 120 months. The outcome variable contains two measurements: one is the age in months (ageinmonths_test) when a secondary questionnaire was administered, while another is a parallel of this but states the actual date (date_test) in YYMMDD10 format (ex. 2012-01-22 or January 22, 2012).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to know how to I can produce different datasets by restricting to only those ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) between 10 months to 50 months&lt;/P&gt;&lt;P&gt;2) between 10 months to AT LEAST 8 months prior to their secondary questionnaire testing date&lt;/P&gt;&lt;P&gt;3) between 10 months to AT LEAST 4 months prior to their secondary questionnaire testing date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to do the first one through the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test1;
set original;
if ageinmonths &amp;lt;10 then delete;
if ageinmonths &amp;gt;50 then delete;
run;&lt;/PRE&gt;&lt;P&gt;However, I'm having trouble figuring out the 2nd and 3rd bits (most likely due to my lack of SAS knowledge). I've tried to do something similar as the code above but it didn't seem to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test2;
set original;
if ageinmonths &amp;lt;12 AND ageinmonths_test &amp;lt;8 then keep;
else delete;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case, any help would be much appreciated! Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jan 2020 15:22:49 GMT</pubDate>
    <dc:creator>asgee</dc:creator>
    <dc:date>2020-01-22T15:22:49Z</dc:date>
    <item>
      <title>How do I subset a dataset using a range of conditions that contains "at least"?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619185#M19344</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First time user and still a newbie at SAS. I'm working on just basic descriptives on a dataset that contains 50+ variables with&amp;nbsp; age in months (ageinmonths) as a variable ranging from 1 months to 120 months. The outcome variable contains two measurements: one is the age in months (ageinmonths_test) when a secondary questionnaire was administered, while another is a parallel of this but states the actual date (date_test) in YYMMDD10 format (ex. 2012-01-22 or January 22, 2012).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to know how to I can produce different datasets by restricting to only those ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) between 10 months to 50 months&lt;/P&gt;&lt;P&gt;2) between 10 months to AT LEAST 8 months prior to their secondary questionnaire testing date&lt;/P&gt;&lt;P&gt;3) between 10 months to AT LEAST 4 months prior to their secondary questionnaire testing date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to do the first one through the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test1;
set original;
if ageinmonths &amp;lt;10 then delete;
if ageinmonths &amp;gt;50 then delete;
run;&lt;/PRE&gt;&lt;P&gt;However, I'm having trouble figuring out the 2nd and 3rd bits (most likely due to my lack of SAS knowledge). I've tried to do something similar as the code above but it didn't seem to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test2;
set original;
if ageinmonths &amp;lt;12 AND ageinmonths_test &amp;lt;8 then keep;
else delete;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case, any help would be much appreciated! Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 15:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619185#M19344</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-01-22T15:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subset a dataset using a range of conditions that contains "at least"?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619192#M19346</link>
      <description>&lt;P&gt;If date_test is stored as a SAS date, then you can use the INTNX function to specify a date that is 8 months (or 4 months) prior.&lt;/P&gt;
&lt;P&gt;See the article &lt;A href="https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html" target="_self"&gt;"INTCK and INTNX: Two essential functions for computing intervals between dates in SAS"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Here is an example that shows how to count back 8 months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Y;
format Date_test Prior8 Date10.;
date_test = '08Aug2020'd;
Prior8 = intnx('month', date_test, -8, 'same');
output;
date_test = '31Oct2020'd;
Prior8 = intnx('month', date_test, -8, 'same');
output;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because some months have 28/29 or 30 days whereas others have 31, the "8 months prior" will adjust the date in certain circumstances. In the second example, I ask for 8 months prior to 31Oct. Because 8 month prior is February and because February never has 31 days, the result will be the last day in February (28 or 29, accounting for leap years).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 15:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619192#M19346</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-01-22T15:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subset a dataset using a range of conditions that contains "at least"?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619193#M19347</link>
      <description>&lt;P&gt;The KEEP statement is not an executable statement - it tells SAS what variables to include in the output data set.&amp;nbsp; And because it is the sas compiler (not the executor) that honors your KEEP statement (see below), it is a standalone statement - it can't be the result of an IF test.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set sashelp.class;
  keep  name sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words, KEEP is not the opposite of DELETE.&amp;nbsp; You want the OUTPUT statement.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 15:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-subset-a-dataset-using-a-range-of-conditions-that/m-p/619193#M19347</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-22T15:50:04Z</dc:date>
    </item>
  </channel>
</rss>

