<?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: Update charge amount based on different timeline and multiply factors? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863951#M341215</link>
    <description>&lt;P&gt;Keep the begindates, enddates and factors in a separate dataset.&lt;/P&gt;
&lt;P&gt;At _N_ = 1 in a data step, read the dataset into an array indexed by dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array factors {'01jan1900'd:'31dec2099'd} _temporary_;
if _n_ = 1 then do until (done);
  set factors end=done;
  do _n_ = begindate to enddate;
    factors{_n_} = if;
  enđ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Later in the code, you can then retrieve the factor for every testdate from the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: added _TEMPORARY_ option to ARRAY statement.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 08:17:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-03-14T08:17:14Z</dc:date>
    <item>
      <title>Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863923#M341205</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to update the "ED_charge / INP_charge / ICU_charge" in the sample dataset below (1st SAS code) based on the different timelines and IF factors (2nd SAS code).&amp;nbsp; For example, the new "ED_charge_ / INP_charge_ / ICU_charge_" columns will all multiply by 1.25 because the test date is in the range between 01JAN2016'&amp;lt;= TestDate &amp;lt;= '31MAR2016'.&amp;nbsp; Please help me to approach it; thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data charge;
input ID $ TestDate:ddmmyy10. ED_charge INP_charge ICU_charge;
format TestDate ddmmyy10.;
datalines;
LLL 01/04/2016 1780 1200 4000
UUU 03/09/2017 3000 5000 8000
OOO 09/08/2018 5900 2400 5000
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;if '01JAN2016'd &amp;lt;= TestDate &amp;lt;= '31MAR2016'd then IF= 1.25;
if '01MAR2017'd &amp;lt;= TestDate &amp;lt;= '31MAY2017'd then IF= 1.24;
if '01SEP2018'd &amp;lt;= TestDate &amp;lt;= '31DEC2018'd then IF= 1.23;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 02:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863923#M341205</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-14T02:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863926#M341208</link>
      <description>In addition, the real dataset includes over ten different categories of charges and a dozen different conditions IF factors.  Is it good to do an array or loop?</description>
      <pubDate>Tue, 14 Mar 2023 02:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863926#M341208</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-14T02:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863951#M341215</link>
      <description>&lt;P&gt;Keep the begindates, enddates and factors in a separate dataset.&lt;/P&gt;
&lt;P&gt;At _N_ = 1 in a data step, read the dataset into an array indexed by dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array factors {'01jan1900'd:'31dec2099'd} _temporary_;
if _n_ = 1 then do until (done);
  set factors end=done;
  do _n_ = begindate to enddate;
    factors{_n_} = if;
  enđ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Later in the code, you can then retrieve the factor for every testdate from the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: added _TEMPORARY_ option to ARRAY statement.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 08:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/863951#M341215</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-14T08:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864051#M341247</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Inflation (Date1, Date2, IF);
data Charge_update;
	set charge;

	if '&amp;amp;Date1.'d &amp;lt;= TestDate &amp;lt;= '&amp;amp;Date2.'d then do;
	Inflation_Factor= &amp;amp;IF.;
	array vars ED_charge INP_charge ICU_charge;
	array vars_ ED_charge_ INP_charge_ ICU_charge_;
	do i=1 to dim(vars);
		vars_(i)=vars(i)*Inflation_Factor;
	end;
	end;

	drop i;

run;
%mend;
%Inflation (01JAN2016,31MAR2016,1.25);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864051#M341247</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-14T13:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864052#M341248</link>
      <description>&lt;P&gt;I created a code. However, I couldn't get the macro date to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;127  %macro Inflation (Date1, Date2, IF);
128  data Charge_update;
129      set charge;
130
131      if '&amp;amp;Date1.'d &amp;lt;= TestDate &amp;lt;= '&amp;amp;Date2.'d then do;
132      Inflation_Factor= &amp;amp;IF.;
133      array vars ED_charge INP_charge ICU_charge;
134      array vars_ ED_charge_ INP_charge_ ICU_charge_;
135      do i=1 to dim(vars);
136          vars_(i)=vars(i)*Inflation_Factor;
137      end;
138      end;
139  /*  if '01MAR2017'd &amp;lt;= TestDate &amp;lt;= '31MAY2017'd then IF= 1.24;*/
140
141  /*  if '01SEP2018'd &amp;lt;= TestDate &amp;lt;= '31DEC2018'd then IF= 1.23;*/
142
143      drop i;
144
145  run;
146  %mend;
147  %Inflation (01JAN2016,31MAR2016,1.25);
NOTE: Line generated by the invoked macro "INFLATION".
1     data Charge_update;     set charge;      if '&amp;amp;Date1.'d &amp;lt;= TestDate &amp;lt;= '&amp;amp;Date2.'d then do;
                                                  ----------
                                                  77
ERROR 77-185: Invalid number conversion on '&amp;amp;Date1.'d.

1  ! data Charge_update;     set charge;      if '&amp;amp;Date1.'d &amp;lt;= TestDate &amp;lt;= '&amp;amp;Date2.'d then do;
                                                                            ----------
                                                                            77
1  ! Inflation_Factor= &amp;amp;IF.;     array vars ED_charge INP_charge ICU_charge;     array vars_
1  ! ED_charge_ INP_charge_ ICU_charge_;     do i=1 to dim(vars);
ERROR: Invalid date/time/datetime constant '&amp;amp;Date1.'d.
ERROR: Invalid date/time/datetime constant '&amp;amp;Date2.'d.

ERROR 77-185: Invalid number conversion on '&amp;amp;Date2.'d.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CHARGE_UPDATE may be incomplete.  When this step was stopped there were 0
         observations and 9 variables.
WARNING: Data set WORK.CHARGE_UPDATE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864052#M341248</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-14T13:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864065#M341256</link>
      <description>&lt;P&gt;Macro variables do no resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;Macro variables do no resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;Macro variables do no resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;Repeat until it sticks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   if &lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;&amp;amp;Date1.&lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;d &amp;lt;= TestDate &amp;lt;= &lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;&amp;amp;Date2.&lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;d then do;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 14:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864065#M341256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-14T14:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864089#M341266</link>
      <description>&lt;P&gt;Even if you get the macro to work: you will do a pass through your dataset for every single time range. My suggested code does only one pass for all time ranges.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864089#M341266</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-14T15:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864094#M341268</link>
      <description>I'm wondering where I should add your codes.</description>
      <pubDate>Tue, 14 Mar 2023 15:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864094#M341268</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-14T15:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update charge amount based on different timeline and multiply factors?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864098#M341269</link>
      <description>&lt;P&gt;Quote from my post:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;At _N_ = 1 in a data step,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-charge-amount-based-on-different-timeline-and-multiply/m-p/864098#M341269</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-14T15:50:44Z</dc:date>
    </item>
  </channel>
</rss>

