<?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 perform a calculation by comparing dates  when multiple records available in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712322#M219608</link>
    <description>&lt;P&gt;Problem 1: You have datetimes that you store as strings.&lt;/P&gt;
&lt;P&gt;Problem 2: The datetimes don't seem to have a relevant time-information, so maybe that can be dropped.&lt;/P&gt;
&lt;P&gt;Problem 3: You have dates that you store as strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, before i suggest something useless, please explain why you aren't storing data in the best data-type possible. And please check, why it is necessary to have time-data in a variable with 0 information-value.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2021 06:43:11 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-01-19T06:43:11Z</dc:date>
    <item>
      <title>How to perform a calculation by comparing dates  when multiple records available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712314#M219604</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to add data set&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;aa (variable=val)&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;values with dataset &lt;FONT color="#FF6600"&gt;bb&lt;FONT color="#FF0000"&gt;(variable=weight)&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt; values by comparing dates. In my data, subject id=1 has multiple records in dataset&amp;nbsp; &amp;nbsp;aa&amp;nbsp; &amp;nbsp;and bb.&amp;nbsp; &amp;nbsp;I need to derive a variable&amp;nbsp;&lt;FONT color="#FF6600"&gt;&amp;nbsp; sum&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;FONT color="#000000"&gt;for&amp;nbsp; all&amp;nbsp; &amp;nbsp; aa&amp;nbsp; &amp;nbsp;records by adding&amp;nbsp;&lt;FONT color="#FF6600"&gt; val&lt;/FONT&gt; from aa with &lt;FONT color="#FF6600"&gt;weight&amp;nbsp;&lt;/FONT&gt; from bb. But i need to take only&amp;nbsp; bb&amp;nbsp; weight value for each&amp;nbsp; &amp;nbsp;aa record only if wdtc from bb dataset is on or before &lt;FONT color="#FF6600"&gt;dtc&lt;/FONT&gt; from aa dataset .&amp;nbsp; Thank you&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; val&amp;nbsp; &amp;nbsp; dtc&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weight&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum&lt;/P&gt;
&lt;P&gt;1 49 2018-10-16T00:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55.1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104.1&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input id val dtc $19.;
datalines;
1 49 2018-10-16T00:00:00
1 48 2018-10-17T00:00:00
1 44 2020-01-06T00:00:00
1 56 2020-03-16T00:00:00
1 43 2020-03-25T00:00:00
2 46 2020-02-06T00:00:00
2 58 2020-05-16T00:00:00
2 48 2020-07-25T00:00:00
;

data bb;
input id weight wdtc $10.;
datalines;
1 52.1 2018-10-15
1 55.1 2018-10-16
1 51.1 2018-10-17
1 50.1 2020-01-06  
1 52   2020-02-10
1 55   2020-03-25
2 58   2020-02-05
2 60   2020-02-07
2 59.2 2020-05-16
2 59   2020-07-23
2 63   2020-07-24
;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2021 06:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712314#M219604</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2021-01-19T06:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a calculation by comparing dates  when multiple records available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712322#M219608</link>
      <description>&lt;P&gt;Problem 1: You have datetimes that you store as strings.&lt;/P&gt;
&lt;P&gt;Problem 2: The datetimes don't seem to have a relevant time-information, so maybe that can be dropped.&lt;/P&gt;
&lt;P&gt;Problem 3: You have dates that you store as strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, before i suggest something useless, please explain why you aren't storing data in the best data-type possible. And please check, why it is necessary to have time-data in a variable with 0 information-value.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 06:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712322#M219608</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-01-19T06:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a calculation by comparing dates  when multiple records available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712423#M219646</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time.&amp;nbsp; In my previous post i posted what is in my similar actual data. I am again posting the data with numeric date values. Please suggest. Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input id val dtc ;
informat dtc yymmdd10.;
format dtc yymmdd10.;
datalines;
1 49 2018-10-16T00:00:00
1 48 2018-10-17T00:00:00
1 44 2020-01-06T00:00:00
1 56 2020-03-16T00:00:00
1 43 2020-03-25T00:00:00
2 46 2020-02-06T00:00:00
2 58 2020-05-16T00:00:00
2 48 2020-07-25T00:00:00
;

data bb;
input id weight wdtc;
informat wdtc yymmdd10.;
format wdtc yymmdd10.;
datalines;
1 52.1 2018-10-15
1 55.1 2018-10-16
1 51.1 2018-10-17
1 50.1 2020-01-06  
1 52   2020-02-10
1 55   2020-03-25
2 58   2020-02-05
2 60   2020-02-07
2 59.2 2020-05-16
2 59   2020-07-23
2 63   2020-07-24
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2021 15:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712423#M219646</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2021-01-19T15:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a calculation by comparing dates  when multiple records available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712604#M219739</link>
      <description>&lt;P&gt;Looks as if a merge will solve the problem, but you have to sort the data and rename dtc to wdtc or vice versa:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=aa;
   by dtc;
run;

proc sort data=bb;
   by wdtc;
run;

data cc;
   merge aa(rename=(dtc=wdtc) in=inA) bb(in=inB);
   by wdtc;

   if inA and inB;
   sum = val + weight;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 07:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-calculation-by-comparing-dates-when-multiple/m-p/712604#M219739</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-01-20T07:56:42Z</dc:date>
    </item>
  </channel>
</rss>

