<?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: Variable transformation based on exponential decay in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400033#M3555</link>
    <description>My bad! I thought the article would be available under an academic access. Regarding the full drug admin history, I provided that for the patient # 1 in my first table (please see above). I'm not able to provide the history for all patients, because as I said before, there are millions of patients in this data.</description>
    <pubDate>Sat, 30 Sep 2017 21:16:12 GMT</pubDate>
    <dc:creator>Alireza_Boloori</dc:creator>
    <dc:date>2017-09-30T21:16:12Z</dc:date>
    <item>
      <title>Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400008#M3549</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of patients who're prescribed two medications at different time intervals. This is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Patient ID&lt;/U&gt;&amp;nbsp; &amp;nbsp; &lt;U&gt;Drug1_dose&lt;/U&gt;&amp;nbsp; &amp;nbsp; &lt;U&gt;Drug2_dose&lt;/U&gt;&amp;nbsp; &amp;nbsp; &lt;U&gt;Time_start&lt;/U&gt;&amp;nbsp; &amp;nbsp; &lt;U&gt;Time_stop&lt;/U&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/5/2017&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2/17/2017&amp;nbsp; &amp;nbsp; &amp;nbsp;2/25/2017&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/15/2017&amp;nbsp; &amp;nbsp; &amp;nbsp;2/10/2017&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want to apply a weight based on an "exponential decay" function to the drug doses, so that they can be extended over an extra period. Here is the function:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$exp{-(x^2)/(2a^2)}$&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;where "x" is the number of days elapsed since when the drug was prescribed, and a is a constant (a=0.849322). For example, for patient 1, drug 1, the extended drug dose is calculated as follows (extended time windows = 3 days):&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;1/1/17&lt;/TD&gt;&lt;TD&gt;1/2/17&lt;/TD&gt;&lt;TD&gt;1/3/17&lt;/TD&gt;&lt;TD&gt;1/4/17&lt;/TD&gt;&lt;TD&gt;1/5/17&lt;/TD&gt;&lt;TD&gt;1/6/17&lt;/TD&gt;&lt;TD&gt;1/7/17&lt;/TD&gt;&lt;TD&gt;1/8/17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dose_original&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Weight (from 1/1/17)&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0.0625&lt;/TD&gt;&lt;TD&gt;0.001953&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Weight (from 1/2/17)&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0.5&lt;/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t;TD&gt;15&lt;/TD&gt;&lt;TD&gt;15.625&lt;/TD&gt;&lt;TD&gt;15.64453&lt;/TD&gt;&lt;TD&gt;15.64453&lt;/TD&gt;&lt;TD&gt;5.644534&lt;/TD&gt;&lt;TD&gt;0.644532&lt;/TD&gt;&lt;TD&gt;0.019531&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0.5 = exp{-(1^2)/(2*&lt;SPAN&gt;0.849322&lt;/SPAN&gt;^2)}&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;0.0625&lt;/SPAN&gt; = exp{-(2^2)/(2*&lt;SPAN&gt;0.849322&lt;/SPAN&gt;^2)}&lt;/PRE&gt;&lt;PRE&gt;0.001953= exp{-(3^2)/(2*&lt;SPAN&gt;0.849322&lt;/SPAN&gt;^2)}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if there is any way to make this transformation. I Know that the number of rows (observations) may get bigger hyper-exponentially, but I need to have this transformation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any feedback/thoughts, in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2017 16:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400008#M3549</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-09-30T16:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400015#M3550</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Just in your small sample, you have 56 implied dates (1/1 through 2/25).&amp;nbsp; Do you really want 56 columns (as is implied in your sample output)?&amp;nbsp;More generally, if your total date range is 1 year, do you want 365 columns?&amp;nbsp; Perhaps you might prefer a data set organized&amp;nbsp;with just 5 vars, and as many rows as needed to accomodate your decaying weight:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
 input id dose (from_date to_date) (:mmddyy10.) weight;
 format from_date to_date date9.;
datalines;
1 10 1/1/2017 1/1/2017 1
1 10 1/1/2017 1/2/2017 .5
1 10 1/1/2017 1/3/2017 .0625
1 10 1/1/2017 1/4/2017 .001953
1 10 1/2/2017 1/2/2017 1
1 10 1/2/2017 1/3/2017 .5
1 10 1/2/2017 1/4/2017 .0625
1 10 1/2/2017 1/5/2017 .001953
1 10 1/3/2017 1/3/2017 1
1 10 1/3/2017 1/4/2017 .5
1 10 1/3/2017 1/5/2017 .0625
1 10 1/3/2017 1/6/2017 .001953
1 10 1/4/2017 1/4/2017 1
1 10 1/4/2017 1/5/2017 .5
1 10 1/4/2017 1/6/2017 .0625
1 10 1/4/2017 1/7/2017 .001953
1 10 1/5/2017 1/5/2017 1
1 10 1/5/2017 1/6/2017 .5
1 10 1/5/2017 1/7/2017 .0625
1 10 1/5/2017 1/8/2017 .001953
run;
&lt;/CODE&gt;&lt;/PRE&gt;
You could then run a proc tabulate&amp;nbsp;with DOSE as analysis var,&amp;nbsp;class vars of from_date and to_date, and&amp;nbsp;weight&amp;nbsp;as the weighting vars.&amp;nbsp; It would yield a table laid out like your requested result.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=mydata;
 by id;&lt;BR /&gt; class from_date to_date;
 var dose;
 weight weight;
 tables to_date all, from_date*sum*dose=' '*f=best10.6 /rts=12;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;If so, then making MYDATA from your original dataset is&amp;nbsp;fairly simple.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Your sample decay is censored after 3 days.&amp;nbsp; Is that your intention?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 30 Sep 2017 18:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400015#M3550</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-30T18:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400023#M3551</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;Thank you for the response! However, there are a few points that need to be mentioned:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The whole idea behind this step is to prepare the data for conducting "survival analysis."&lt;/LI&gt;&lt;LI&gt;So, although all 3 years are rquired, each patient was prescribed for a specific part of this 3-year period (some had multiple time intervals).&lt;/LI&gt;&lt;LI&gt;The second table I provided was for clarfiying my point (it was not the output I'm looking for). The output I'm looking for has the same structrue as my first table (with the difference that now I've extended dose over extended time period).&lt;/LI&gt;&lt;LI&gt;The "mydata" dataset you created at the beginning of your response cannot be helpful, because (i) it's not generated by a macro, and (ii) for a very large-size data (like mine with millions of patients), it'd be impossible to generate it.&lt;/LI&gt;&lt;LI&gt;The extended time windows for this example was 3 days. However, I may have to change this threshold to try other values.&amp;nbsp;That's another reason that I need a macro.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Sat, 30 Sep 2017 20:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400023#M3551</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-09-30T20:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400028#M3552</link>
      <description>&lt;P&gt;I'm puzzled. Your decay equation is not not one of exponential decay because it is quadratic in time. It is as if molecules that have been in the system for a longer period are eliminated faster than freshly administered drugs. How did you get that decay equation?&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2017 20:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400028#M3552</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-30T20:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400029#M3553</link>
      <description>At any day a drug is prescribed, it'll have delayed exposure in later days. That's where the exponential decay function is applied (here is the source: &lt;A href="https://www.ncbi.nlm.nih.gov/pubmed/16549262" target="_blank"&gt;https://www.ncbi.nlm.nih.gov/pubmed/16549262&lt;/A&gt;). The numbers you see (e.g., 15.625) is the accumulation of all delayed exposure attributed to the previous days (whose numbers are censored by the time window).</description>
      <pubDate>Sat, 30 Sep 2017 20:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400029#M3553</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-09-30T20:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400031#M3554</link>
      <description>&lt;P&gt;Sorry, I don't have 35.95USD to spend on getting access to that article. Do the authors discuss the more than exponential decay rate equation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm picking on this because truly exponential decay is much easier to handle. At any point in time, you only need to know the concentration at that time to&amp;nbsp;predict the concentration at later times. With your equation, you need to know&amp;nbsp;the full drug administration history to predict the concentration at later times.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2017 21:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400031#M3554</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-30T21:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400033#M3555</link>
      <description>My bad! I thought the article would be available under an academic access. Regarding the full drug admin history, I provided that for the patient # 1 in my first table (please see above). I'm not able to provide the history for all patients, because as I said before, there are millions of patients in this data.</description>
      <pubDate>Sat, 30 Sep 2017 21:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400033#M3555</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-09-30T21:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable transformation based on exponential decay</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400183#M3562</link>
      <description>&lt;P&gt;This is how to do this with an array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID D1 D2 (start stop) (:mmddyy10.);
format start stop yymmdd10.;
datalines;
1 10 5 1/1/2017 1/5/2017
1 0 7 2/17/2017 2/25/2017
2 3 0 1/15/2017 2/10/2017
;

/* "decay" constant */
%let a = 0.84932180028801904272150283410289;
/* Decay window (days) */
%let dw = 10;
/* Define total date range, allowing for a decay period at the end */
%let ldate=01jan2017;
%let hdate=10jan2018;

%let lbound=%sysfunc(int("&amp;amp;ldate"d));
%let hbound=%sysfunc(int("&amp;amp;hdate"d));

data want;
format date yymmdd10.;
array dose(&amp;amp;lbound.:&amp;amp;hbound.) _temporary_;
call missing(of dose{*});
do until(last.id);
    set have; by id;
    do date = start to stop;
        do _d = 0 to &amp;amp;dw;
            dose{date + _d} + (D1 * exp(-_d**2/(2*&amp;amp;a**2)));
            end;
        end;
    end;
do date = lbound(dose) to hbound(dose);
    if dose{date} &amp;gt; 0.00001 then do;
        drug_dose = dose{date};
        output;
        end;
    end;
keep id date drug_dose;
run;

proc print; by id; id id; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2017 03:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Variable-transformation-based-on-exponential-decay/m-p/400183#M3562</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-02T03:07:20Z</dc:date>
    </item>
  </channel>
</rss>

