Hello Molla
correction:
The array indexes are the sas date values derived from the date strings(date_begin and date_end) that are read in via the datalines. The input stmt format for date_begin and date_end specify that these values are sas dates. Date_begin value 04/04/2009 is sas date 17991. For each patient entry, the loop goes from the sas date value for the date_begin to the sas date value for the date_end and adds the dose amount to EACH array element in the date range span. That is what the code is doing, whether correct or not. So for patient id 1 with a date_begin of 04/04/2009( sas date 17991) and date_end of 12/12/2009( sas date 18243), the Dose amount of 1 will be added to EACH array value from drug_day1 to drug_day252, since there are 252 days from date_begin to date_end for the entry that is '1 B 1 04/04/2009 12/12/2009'. So the array index can be viewed explicitly as drug_day[17991] thru drug_day[18243] or drug_day1 thru drug_day252. For each observation that corresponds to an input record in this example, a temporary array is created with a lower bound of the minimum date value of all the date values in the dataset and a upper bound of the maximum date in the dataset. But only the actual date_begin index thru the actual date_end index are assigned values in the temporary array. So in the case of entry '2 X 5 06/08/2009 09/09/2010', drug_day66 to drug_day524 or drug_day [18056] thru drug_day[18514] will only have values since there are 458 days from date_begin to date_end. Check how SAS treats dates and SAS array references.
Paste the code into SAS UNIV Edition editor and step thru it. You will have to add an end statement after drug_day[dt]+dose and remove the ';' after the last datalines entry.
... View more