<?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 Filling in missing dose and month medication data - Lagging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706785#M216977</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help formatting my data for Proc Traj. I have steroid data during a 1 year period, and I have dose information as well as the amount of steroid supplied (days_supp). I am trying to get my dataset clean so that every month is recorded properly, however my data is fairly messy. This is a small example of what I am working with and what I would like it to be:&lt;/P&gt;&lt;PRE&gt;data have;
input id month dose days_supp;
datalines;
1 1 1 90
1 2 5 90
1 3 . .
1 4 . .
1 5 4 30
1 6 6 90
1 7 . .
1 8 . .
1 9 . .
1 10 2 30
1 11 3 30
1 12 . .
2 1 . .
2 2 5 60
2 3 2 30
2 4 . .
2 5 . .
2 6 . .
2 7 5 30
2 8 . .
2 9 5 30
2 10 5 30
2 11 5 30
2 12 5 30
;
run;

data want;
input id month dose days_supp;
datalines;
1 1 1 30
1 2 1 30
1 3 1 30
1 4 5 30
1 5 5 30
1 6 5 30
1 7 4 30
1 8 6 30
1 9 6 30
1 10 6 30
1 11 2 30
1 12 3 30
2 1 . .
2 2 5 30
2 3 5 30
2 4 2 30
2 5 . .
2 6 . .
2 7 5 30
2 8 . .
2 9 5 30
2 10 5 30
2 11 5 30
2 12 5 30
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, if someone got a 90 day supply on month 1, that dose should be present for month 1, 2, and 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data month_lag;
	set un_t_month;
	dose_lag=lag(avg_dose);
	supp_lag=lag(days_supp);
	dose_lag2=lag(dose_lag);
	supp_lag2=lag(supp_lag);
	dose_lag3=lag(dose_lag2);
	supp_lag3=lag(supp_lag2);
	if 35&amp;lt;supp_lag&amp;lt;61 and _name_ ^= "dose12" and avg_dose=. then do;
		avg_dose=dose_lag;
		days_supp=supp_lag-30;
		avg_dose=(avg_dose*days_supp)/30;
	end;
	else if 61&amp;lt;supp_lag&amp;lt;91 and _name_ not in ("dose12","dose11") and avg_dose=. then do;
		avg_dose=dose_lag;
		days_supp=supp_lag-60;
		avg_dose=(avg_dose*days_supp)/30;
	end;
	else if 61&amp;lt;supp_lag2&amp;lt;91 and _name_ not in ("dose12", "dose11") and avg_dose=. then do;
		avg_dose=dose_lag2;
		days_supp=supp_lag2-60;
		avg_dose=(avg_dose*days_supp)/30;
	end;
run;&lt;/PRE&gt;&lt;P&gt;But this doesn't work when I have multiple large days supplies next to each other (i.e. 90 on month 1 and 90 on month 2). Also it's very inefficient code I'm sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated. I also have the data transposed in case it's better to approach it that way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Dec 2020 20:34:56 GMT</pubDate>
    <dc:creator>alpine_nights</dc:creator>
    <dc:date>2020-12-17T20:34:56Z</dc:date>
    <item>
      <title>Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706785#M216977</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help formatting my data for Proc Traj. I have steroid data during a 1 year period, and I have dose information as well as the amount of steroid supplied (days_supp). I am trying to get my dataset clean so that every month is recorded properly, however my data is fairly messy. This is a small example of what I am working with and what I would like it to be:&lt;/P&gt;&lt;PRE&gt;data have;
input id month dose days_supp;
datalines;
1 1 1 90
1 2 5 90
1 3 . .
1 4 . .
1 5 4 30
1 6 6 90
1 7 . .
1 8 . .
1 9 . .
1 10 2 30
1 11 3 30
1 12 . .
2 1 . .
2 2 5 60
2 3 2 30
2 4 . .
2 5 . .
2 6 . .
2 7 5 30
2 8 . .
2 9 5 30
2 10 5 30
2 11 5 30
2 12 5 30
;
run;

data want;
input id month dose days_supp;
datalines;
1 1 1 30
1 2 1 30
1 3 1 30
1 4 5 30
1 5 5 30
1 6 5 30
1 7 4 30
1 8 6 30
1 9 6 30
1 10 6 30
1 11 2 30
1 12 3 30
2 1 . .
2 2 5 30
2 3 5 30
2 4 2 30
2 5 . .
2 6 . .
2 7 5 30
2 8 . .
2 9 5 30
2 10 5 30
2 11 5 30
2 12 5 30
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, if someone got a 90 day supply on month 1, that dose should be present for month 1, 2, and 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data month_lag;
	set un_t_month;
	dose_lag=lag(avg_dose);
	supp_lag=lag(days_supp);
	dose_lag2=lag(dose_lag);
	supp_lag2=lag(supp_lag);
	dose_lag3=lag(dose_lag2);
	supp_lag3=lag(supp_lag2);
	if 35&amp;lt;supp_lag&amp;lt;61 and _name_ ^= "dose12" and avg_dose=. then do;
		avg_dose=dose_lag;
		days_supp=supp_lag-30;
		avg_dose=(avg_dose*days_supp)/30;
	end;
	else if 61&amp;lt;supp_lag&amp;lt;91 and _name_ not in ("dose12","dose11") and avg_dose=. then do;
		avg_dose=dose_lag;
		days_supp=supp_lag-60;
		avg_dose=(avg_dose*days_supp)/30;
	end;
	else if 61&amp;lt;supp_lag2&amp;lt;91 and _name_ not in ("dose12", "dose11") and avg_dose=. then do;
		avg_dose=dose_lag2;
		days_supp=supp_lag2-60;
		avg_dose=(avg_dose*days_supp)/30;
	end;
run;&lt;/PRE&gt;&lt;P&gt;But this doesn't work when I have multiple large days supplies next to each other (i.e. 90 on month 1 and 90 on month 2). Also it's very inefficient code I'm sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated. I also have the data transposed in case it's better to approach it that way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 20:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706785#M216977</guid>
      <dc:creator>alpine_nights</dc:creator>
      <dc:date>2020-12-17T20:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706791#M216990</link>
      <description>&lt;P&gt;From what I see with the "pattern" of missing data it looks to me as if something read a file incorrectly and moved lines up for your "dose" and "days" information.&lt;/P&gt;
&lt;P&gt;Can you share some lines of the source data with any personal identification&amp;nbsp; information removed and share how your read that source?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 20:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706791#M216990</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-17T20:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706794#M216991</link>
      <description>&lt;P&gt;This is very messy medicaid data. The individuals have several steroid use observations at different dates, and I used this code to create months based on a specific one year time interval:&lt;/P&gt;&lt;PRE&gt;data month_data;
	set steroid_cohort;
	if steroid_dt^=.;
	if 0&amp;lt;=steroid_dt-index_dt&amp;lt;=30 then month=1;
	else if 30&amp;lt;steroid_dt-index_dt&amp;lt;=60 then month=2;
	else if 60&amp;lt;steroid_dt-index_dt&amp;lt;=90 then month=3;
	else if 90&amp;lt;steroid_dt-index_dt&amp;lt;=120 then month=4;
	else if 120&amp;lt;steroid_dt-index_dt&amp;lt;=150 then month=5;
	else if 150&amp;lt;steroid_dt-index_dt&amp;lt;=180 then month=6;
	else if 180&amp;lt;steroid_dt-index_dt&amp;lt;=210 then month=7;
	else if 210&amp;lt;steroid_dt-index_dt&amp;lt;=240 then month=8;
	else if 240&amp;lt;steroid_dt-index_dt&amp;lt;=270 then month=9;
	else if 270&amp;lt;steroid_dt-index_dt&amp;lt;=300 then month=10;
	else if 300&amp;lt;steroid_dt-index_dt&amp;lt;=330 then month=11;
	else if 330&amp;lt;steroid_dt-index_dt&amp;lt;=365 then month=12;
	datediff=steroid_dt-index_dt;
run; &lt;/PRE&gt;&lt;P&gt;With steroid_dt being the date of the visit where steroids were prescribed, and index date being the diagnosis date of the disease I am looking at.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the data I started with for the first individual. Month is the variable I created&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alpine_nights_0-1608238662043.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52773iA1B326A052794DCF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="alpine_nights_0-1608238662043.png" alt="alpine_nights_0-1608238662043.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 20:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706794#M216991</guid>
      <dc:creator>alpine_nights</dc:creator>
      <dc:date>2020-12-17T20:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706798#M216993</link>
      <description>&lt;P&gt;SAS programmers call this a 'Do "&lt;EM&gt;Whitlock&lt;/EM&gt;" loop'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (Keep=id month dose days_supp);
  if 0 then set have;
  month=1;
  do until (last.id);
    set have (rename=(days_supp=old_days_supp month=old_month));
      by id;
    if old_days_supp =. 
      then old_days_supp =0;
    do i=old_days_supp to 30 by -30;
      days_supp=30;
      output;
      month=month+1;
    end; 
    if old_month&amp;gt;=month then do;
      month=old_month;
      days_supp=.;
      output;
      month+1;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 21:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706798#M216993</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-17T21:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706799#M216994</link>
      <description>&lt;P&gt;found a bug, and edited my code above.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 21:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706799#M216994</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-17T21:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706800#M216995</link>
      <description>&lt;P&gt;This is perfect, thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 21:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706800#M216995</guid>
      <dc:creator>alpine_nights</dc:creator>
      <dc:date>2020-12-17T21:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706802#M216997</link>
      <description>&lt;P&gt;Glad you get a working solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warning: Leap days can potentially create a value with no "month" at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are calculating Datediff, why not do it before all that "if then else" and use it instead of repeatedly typing the same subtraction?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 21:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706802#M216997</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-17T21:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missing dose and month medication data - Lagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706805#M216999</link>
      <description>&lt;P&gt;Ah yes, datediff was something I added after the fact for checking purposes, that's a great idea thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 21:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missing-dose-and-month-medication-data-Lagging/m-p/706805#M216999</guid>
      <dc:creator>alpine_nights</dc:creator>
      <dc:date>2020-12-17T21:46:28Z</dc:date>
    </item>
  </channel>
</rss>

