<?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: Subsetting by drug usage (past, previous, current) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771820#M244980</link>
    <description>&lt;P&gt;It would seem to me that you're going to need to make a flag for ever drug use. You can get an ever flag a couple of different ways. Most common is probably proc sql or retain statement.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Oct 2021 19:03:31 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2021-10-03T19:03:31Z</dc:date>
    <item>
      <title>Subsetting by drug usage (past, previous, current)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771794#M244972</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset where I have years 0-8 and am only interested in years 0-2 for now. I want to compare between subjects who never used drugs and subjects who are currently using drugs (at year 2). I also need to compare between subjects who did not report drug use at year 2, but have reported drug use previously to the subjects who have never reported drug use.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;drug use variable: hard_drugs&lt;/P&gt;&lt;P&gt;Time variable: years&lt;/P&gt;&lt;P&gt;Also, the same subjects were followed over 8 years, so there are repeated measures.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this code below to get the current drug users.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CurrentDrugUsers;
SET PROJECT1.INPUT;
WHERE years = 2 AND hard_drugs = 1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was able to get subjects who are currently not taking drugs, however, I cannot separate them into "previous" vs "never" groups.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA NeverDrugUsers;
SET PROJECT1.INPUT;
IF years = 2 AND hard_drugs = 0 ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Oct 2021 23:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771794#M244972</guid>
      <dc:creator>mdakkak</dc:creator>
      <dc:date>2021-10-02T23:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting by drug usage (past, previous, current)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771798#M244974</link>
      <description>&lt;P&gt;Providing sample data and the desired result reduces ambiguity. Below two options for how I understand your question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input subject $ year hard_drugs;
  datalines;
a 0 0
a 1 0
a 2 0
b 0 1
b 1 0
b 2 0
c 0 0
c 1 1
c 2 1
;

/* option 1 */
proc sort data=have out=inter;
  by subject year;
  where year&amp;lt;=2;
run;

data want_1;
  set inter;
  by subject year;
  retain past_hard_drugs_flg 0;
  if hard_drugs=1 then past_hard_drugs_flg=1;
  if last.subject then
    do;
      output;
      past_hard_drugs_flg=0;
    end;
run;


/* option 2 */
data want_2;
  if _n_=1 then 
    do;
      dcl hash h1(dataset:'have(where=(year&amp;lt;2 and hard_drugs=1))');
      h1.defineKey('subject');
      h1.defineDone();
    end;

  set have (where=(year=2));
  past_hard_drugs_flg= not h1.check();
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Oct 2021 00:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771798#M244974</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-03T00:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting by drug usage (past, previous, current)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771820#M244980</link>
      <description>&lt;P&gt;It would seem to me that you're going to need to make a flag for ever drug use. You can get an ever flag a couple of different ways. Most common is probably proc sql or retain statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Oct 2021 19:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-by-drug-usage-past-previous-current/m-p/771820#M244980</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-10-03T19:03:31Z</dc:date>
    </item>
  </channel>
</rss>

