<?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 keeping one observation per drug per patient in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264625#M51936</link>
    <description>&lt;P&gt;I have two datasets one represent med use before a specific data and one after. I coded the use of each med as 0/1. I want to combine the two dataset and create one dataset that tell me whether each id had at least one of each of the med before and another column that tell me wether they had at least one of the same med after&lt;/P&gt;&lt;P&gt;Here is my data&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dataset 1

id  drug   med_11pre    med_22pre  med_23pre    
1   11         1                  0                    0 
1    11        1                  0                    0
1    11        1                  0                    0
1    22        0                 1                    0
1   22         0                 1                    0
2   11          1                0                   0    
2   22         0                 0                    =0
2  23          0                 0                    1
2  23          0                0                    1 
2  25          0                0                    1

dataset 2
id  drug   med_11post    med_22post  med_23ost med_12post    
1   11         1                  0                    0                          0
1    12        0                  0                    0                          1
1    13       0                   0                    0                          0
1    22        0                 1                    0                           0
1   22         0                 1                    0                           0
2   11          1                0                   0                            0
2   22         0                 0                    0                        0
2  23          0                 0                    1                        0
2  23          0                0                    1                          0
2  25          0                0                    1                         0

 I want an output that look like this:
id med_11pre med_11post    med_12pre med12post
1               1            1               0                    1
2               1            1               0                    0

which mean give each id 0 if they have none during that period and 1 if they have any during that period. 
Thanks! 


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Apr 2016 16:58:10 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2016-04-18T16:58:10Z</dc:date>
    <item>
      <title>keeping one observation per drug per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264625#M51936</link>
      <description>&lt;P&gt;I have two datasets one represent med use before a specific data and one after. I coded the use of each med as 0/1. I want to combine the two dataset and create one dataset that tell me whether each id had at least one of each of the med before and another column that tell me wether they had at least one of the same med after&lt;/P&gt;&lt;P&gt;Here is my data&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dataset 1

id  drug   med_11pre    med_22pre  med_23pre    
1   11         1                  0                    0 
1    11        1                  0                    0
1    11        1                  0                    0
1    22        0                 1                    0
1   22         0                 1                    0
2   11          1                0                   0    
2   22         0                 0                    =0
2  23          0                 0                    1
2  23          0                0                    1 
2  25          0                0                    1

dataset 2
id  drug   med_11post    med_22post  med_23ost med_12post    
1   11         1                  0                    0                          0
1    12        0                  0                    0                          1
1    13       0                   0                    0                          0
1    22        0                 1                    0                           0
1   22         0                 1                    0                           0
2   11          1                0                   0                            0
2   22         0                 0                    0                        0
2  23          0                 0                    1                        0
2  23          0                0                    1                          0
2  25          0                0                    1                         0

 I want an output that look like this:
id med_11pre med_11post    med_12pre med12post
1               1            1               0                    1
2               1            1               0                    0

which mean give each id 0 if they have none during that period and 1 if they have any during that period. 
Thanks! 


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 16:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264625#M51936</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-04-18T16:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: keeping one observation per drug per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264631#M51937</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have1; /* your "dataset 1" */
by id;
var med:;
output out=aggreg1(drop=_:) max=;
run;

proc summary data=have2; /* your "dataset 2" */
by id;
var med:;
output out=aggreg2(drop=_:) max=;
run;

data want;
merge aggreg:;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the column order in dataset WANT is important to you, we'll have to add code to rearrange the variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 17:34:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264631#M51937</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-18T17:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: keeping one observation per drug per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264641#M51938</link>
      <description>&lt;P&gt;This is code to rearrange the variables in dataset WANT to ID, med11pre, med11post, med12pre, med12post, etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :varlist separated by ' '
from dictionary.columns
where libname='WORK' &amp;amp; memname='WANT' /* Please replace WORK and WANT by your libname and dataset name. */
order by tranwrd(name,'r','a'); /* This is to sort "pre" before "post". */
quit;

data want;
retain &amp;amp;varlist;
set want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2016 18:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264641#M51938</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-18T18:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: keeping one observation per drug per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264644#M51939</link>
      <description>Thank you FreelanceReinhard as always a lifesaver!</description>
      <pubDate>Mon, 18 Apr 2016 18:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keeping-one-observation-per-drug-per-patient/m-p/264644#M51939</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-04-18T18:21:34Z</dc:date>
    </item>
  </channel>
</rss>

