<?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 LOCF but with conditions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582295#M75695</link>
    <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got stuck at one step in my program. I have two datasets one have the subject number and its weight measurement on various dates.&lt;/P&gt;&lt;P&gt;Another dataset has the subject number and exposure date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to create a dataset which gives me the weight of a subject on the exposure date, if weight is not taken on the same exposure date and time then have to take the last weight taken for that subject before the exposure date and time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are two datasets...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data weight;&lt;BR /&gt;length subjid $8 vsdtc $16 weight 8;&lt;BR /&gt;input subjid vsdtc weight;&lt;BR /&gt;datalines;&lt;BR /&gt;1001 2018-03-09T13:30 10&lt;BR /&gt;1001 2018-05-02T10:00 12&lt;BR /&gt;1001 2018-08-09T16:00 14&lt;BR /&gt;1002 2018-01-01T12:00 6&lt;BR /&gt;1002 2018-04-01T13:00 8&lt;BR /&gt;1002 2018-05-01T14:00 10&lt;BR /&gt;1002 2018-06-01T12:00 11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data ex;&lt;BR /&gt;length subjid $8 exdtc $16;&lt;BR /&gt;input subjid exdtc;&lt;BR /&gt;datalines;&lt;BR /&gt;1001 2018-04-09T13:30&lt;BR /&gt;1001 2018-05-01T10:00&lt;BR /&gt;1001 2018-08-10T16:00&lt;BR /&gt;1001 2018-08-10T16:00&lt;BR /&gt;1002 2018-01-01T12:00&lt;BR /&gt;1002 2018-04-01T12:00&lt;BR /&gt;1002 2018-06-03&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need final dataset as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp; exdtc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;2018-04-09T13:30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;BR /&gt;1001&amp;nbsp; &amp;nbsp;2018-05-01T10:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;BR /&gt;1001&amp;nbsp; &amp;nbsp;2018-08-10T16:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;2018-08-10T16:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-01-01T12:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-04-01T12:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-06-03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Thank you"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2019 02:05:28 GMT</pubDate>
    <dc:creator>sonicview</dc:creator>
    <dc:date>2019-08-20T02:05:28Z</dc:date>
    <item>
      <title>LOCF but with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582295#M75695</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got stuck at one step in my program. I have two datasets one have the subject number and its weight measurement on various dates.&lt;/P&gt;&lt;P&gt;Another dataset has the subject number and exposure date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to create a dataset which gives me the weight of a subject on the exposure date, if weight is not taken on the same exposure date and time then have to take the last weight taken for that subject before the exposure date and time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are two datasets...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data weight;&lt;BR /&gt;length subjid $8 vsdtc $16 weight 8;&lt;BR /&gt;input subjid vsdtc weight;&lt;BR /&gt;datalines;&lt;BR /&gt;1001 2018-03-09T13:30 10&lt;BR /&gt;1001 2018-05-02T10:00 12&lt;BR /&gt;1001 2018-08-09T16:00 14&lt;BR /&gt;1002 2018-01-01T12:00 6&lt;BR /&gt;1002 2018-04-01T13:00 8&lt;BR /&gt;1002 2018-05-01T14:00 10&lt;BR /&gt;1002 2018-06-01T12:00 11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data ex;&lt;BR /&gt;length subjid $8 exdtc $16;&lt;BR /&gt;input subjid exdtc;&lt;BR /&gt;datalines;&lt;BR /&gt;1001 2018-04-09T13:30&lt;BR /&gt;1001 2018-05-01T10:00&lt;BR /&gt;1001 2018-08-10T16:00&lt;BR /&gt;1001 2018-08-10T16:00&lt;BR /&gt;1002 2018-01-01T12:00&lt;BR /&gt;1002 2018-04-01T12:00&lt;BR /&gt;1002 2018-06-03&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need final dataset as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp; exdtc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;2018-04-09T13:30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;BR /&gt;1001&amp;nbsp; &amp;nbsp;2018-05-01T10:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;BR /&gt;1001&amp;nbsp; &amp;nbsp;2018-08-10T16:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;2018-08-10T16:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-01-01T12:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-04-01T12:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp;2018-06-03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Thank you"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 02:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582295#M75695</guid>
      <dc:creator>sonicview</dc:creator>
      <dc:date>2019-08-20T02:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF but with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582298#M75696</link>
      <description>&lt;P&gt;Just one SQL is needed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data weight;
length subjid $8 vsdtc $16 weight 8;
input subjid vsdtc weight;
datalines;
1001 2018-03-09T13:30 10
1001 2018-05-02T10:00 12
1001 2018-08-09T16:00 14
1002 2018-01-01T12:00 6
1002 2018-04-01T13:00 8
1002 2018-05-01T14:00 10
1002 2018-06-01T12:00 11
;
run;

 

data ex;
length subjid $8 exdtc $16;
input subjid exdtc;
datalines;
1001 2018-04-09T13:30
1001 2018-05-01T10:00
1001 2018-08-10T16:00
1002 2018-01-01T12:00
1002 2018-04-01T12:00
1002 2018-06-03
;
run;

proc sql;
create table final as 
select a.*,Weight
from ex as a, weight as b 
where a.subjid=b.subjid	and vsdtc&amp;lt;=exdtc
group by a.subjid, exdtc
having max( b.vsdtc)= b.vsdtc
order by a.subjid, exdtc, vsdtc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2019 01:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582298#M75696</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-20T01:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: LOCF but with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582300#M75697</link>
      <description>&lt;P&gt;It wouldn't shock me if a DATA step turned out to be considerably faster than SQL.&amp;nbsp; Assuming your data sets are sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set weight (in=inw) ex (in=inx);
by subjid vsdtc;
retain latest_weight;
drop weight;
if first.subjid then latest_weight = .;
if inw then latest_weight = weight;
if inx;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2019 01:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LOCF-but-with-conditions/m-p/582300#M75697</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-20T01:51:43Z</dc:date>
    </item>
  </channel>
</rss>

