Here is my program:
1472 data first_use4;
1473 set wkspace.first_use3;
1474 end_f = srvc_dt+11;
1475 format end_f mmddyy10.;
1476 array months_12 (120) $ buyin01 - buyin120;
1477 drug_index = month(srvc_dt) + (12 * (year(srvc_dt) - 2006));
1478 end_index = month(end_f) + (12 * (year(end_f)- 2006));/*This will ensure at least 12
1478! months of follow-up*/
1479 cov_ab_12=1;
1480 do j = (drug_index - 12) to end_index;
1481 if months_12 {j} in ("0","1","2","A","B") then do;
1482 cov_ab_12=0; /* exclude the current patient */
1483 leave; /* break out of the DO loop */
1484 end;
1485 end;
I am getting the following error.
ERROR: Array subscript out of range at line 1481 column 8.
I ran the same program successfully a day ago and now I am getting this error.
I changed the following statements:
1480 do j = (drug_index - 12) to end_index;
/* (previously) do j=(drug_index-6) to end_index;*/
1481 if months_12 {j} in ("0","1","2","A","B") then do;
/* (previously) if months_12 {j} not in ("3","C");*/
Any input will be very helpful.
The log will also tell you what J was at that record, can you include the full log?
I doubt your loop is doing what you think because it's a number (not a SAS date though) and you can't subtract them to get duration.
Thanks Reeza!
Here is the full log:
ERROR: Array subscript out of range at line 1521 column 8.
bene_id=eeeeee119EAh1rJ srvc_dt=12/22/2015 end_dt=01/20/2016 dayssply=30 drg_name=slz BUYIN01=
BUYIN02= BUYIN03= BUYIN04= BUYIN05= BUYIN06= BUYIN07= BUYIN08= BUYIN09= BUYIN10=
BUYIN11= BUYIN12= HMOIND01= HMOIND02= HMOIND03= HMOIND04= HMOIND05= HMOIND06= HMOIND07=
HMOIND08= HMOIND09= HMOIND10= HMOIND11= HMOIND12= CNTRCT01= CNTRCT02= CNTRCT03= CNTRCT04=
CNTRCT05= CNTRCT06= CNTRCT07= CNTRCT08= CNTRCT09= CNTRCT10= CNTRCT11= CNTRCT12= buyin13=
buyin14= buyin15= buyin16= buyin17= buyin18= buyin19= buyin20= buyin21= buyin22=
buyin23= buyin24= hmoind13= hmoind14= hmoind15= hmoind16= hmoind17= hmoind18= hmoind19=
hmoind20= hmoind21= hmoind22= hmoind23= hmoind24= cntrct13= cntrct14= cntrct15= cntrct16=
cntrct17= cntrct18= cntrct19= cntrct20= cntrct21= cntrct22= cntrct23= cntrct24= buyin25=
buyin26= buyin27= buyin28= buyin29= buyin30= buyin31= buyin32= buyin33= buyin34=
buyin35= buyin36= hmoind25= hmoind26= hmoind27= hmoind28= hmoind29= hmoind30= hmoind31=
hmoind32= hmoind33= hmoind34= hmoind35= hmoind36= cntrct25= cntrct26= cntrct27= cntrct28=
cntrct29= cntrct30= cntrct31= cntrct32= cntrct33= cntrct34= cntrct35= cntrct36= buyin97=C
buyin98=C buyin99=C buyin100=C buyin101=C buyin102=C buyin103=C buyin104=C buyin105=C buyin106=C
buyin107=C buyin108=C hmoind97=0 hmoind98=0 hmoind99=0 hmoind100=0 hmoind101=0 hmoind102=0
hmoind103=0 hmoind104=0 hmoind105=0 hmoind106=0 hmoind107=0 hmoind108=0 cntrct97=S5921
cntrct98=S5921 cntrct99=S5921 cntrct100=S5921 cntrct101=S5921 cntrct102=S5921 cntrct103=S5921
cntrct104=S5921 cntrct105=S5921 cntrct106=S5921 cntrct107=S5921 cntrct108=S5921 buyin109=C
buyin110=C buyin111=C buyin112=C buyin113=C buyin114=C buyin115=C buyin116=C buyin117=C buyin118=C
buyin119=C buyin120=C hmoind109=0 hmoind110=0 hmoind111=0 hmoind112=0 hmoind113=0 hmoind114=0
hmoind115=0 hmoind116=0 hmoind117=0 hmoind118=0 hmoind119=0 hmoind120=0 cntrct109=S5921
cntrct110=S5921 cntrct111=S5921 cntrct112=S5921 cntrct113=S5921 cntrct114=S5921 cntrct115=S5921
cntrct116=S5921 cntrct117=S5921 cntrct118=S5921 cntrct119=S5921 cntrct120=S5921 buyin37=
buyin38= buyin39= buyin40= buyin41= buyin42= buyin43= buyin44= buyin45= buyin46=
buyin47= buyin48= hmoind37= hmoind38= hmoind39= hmoind40= hmoind41= hmoind42= hmoind43=
hmoind44= hmoind45= hmoind46= hmoind47= hmoind48= buyin49= buyin50= buyin51= buyin52=
buyin53= buyin54= buyin55= buyin56= buyin57= buyin58= buyin59= buyin60= hmoind49=
hmoind50= hmoind51= hmoind52= hmoind53= hmoind54= hmoind55= hmoind56= hmoind57= hmoind58=
hmoind59= hmoind60= buyin61= buyin62= buyin63= buyin64= buyin65= buyin66= buyin67=
buyin68= buyin69= buyin70= buyin71= buyin72= hmoind61= hmoind62= hmoind63= hmoind64=
hmoind65= hmoind66= hmoind67= hmoind68= hmoind69= hmoind70= hmoind71= hmoind72= buyin73=
buyin74= buyin75= buyin76= buyin77= buyin78= buyin79= buyin80= buyin81= buyin82=
buyin83= buyin84= hmoind73= hmoind74= hmoind75= hmoind76= hmoind77= hmoind78= hmoind79=
hmoind80= hmoind81= hmoind82= hmoind83= hmoind84= buyin85=0 buyin86=0 buyin87=0 buyin88=0
buyin89=0 buyin90=0 buyin91=C buyin92=C buyin93=C buyin94=C buyin95=C buyin96=C hmoind85=0
hmoind86=0 hmoind87=0 hmoind88=0 hmoind89=0 hmoind90=0 hmoind91=0 hmoind92=0 hmoind93=0 hmoind94=0
hmoind95=0 hmoind96=0 cntrct37= cntrct38= cntrct39= cntrct40= cntrct41= cntrct42= cntrct43=
cntrct44= cntrct45= cntrct46= cntrct47= cntrct48= cntrct49= cntrct50= cntrct51= cntrct52=
cntrct53= cntrct54= cntrct55= cntrct56= cntrct57= cntrct58= cntrct59= cntrct60= cntrct61=
cntrct62= cntrct63= cntrct64= cntrct65= cntrct66= cntrct67= cntrct68= cntrct69= cntrct70=
cntrct71= cntrct72= cntrct73= cntrct74= cntrct75= cntrct76= cntrct77= cntrct78= cntrct79=
cntrct80= cntrct81= cntrct82= cntrct83= cntrct84= cntrct85=0 cntrct86=0 cntrct87=0 cntrct88=0
cntrct89=0 cntrct90=0 cntrct91=N cntrct92=N cntrct93=N cntrct94=X0001 cntrct95=X0001
cntrct96=S5921 count=3 end_f=01/02/2016 drug_index=120 end_index=121 cov_ab_12=1 j=121 cov_d_12=.
_ERROR_=1 _N_=37
The drug_index and end_index variables weren't supposed to to act as dates. They are calculated as numbers to indicate the nth day when the drug was taken. What is confusing is that I didn't get this error when I did "do j = (drug_index - g) to end_index.
drug_index=120 end_index=121 cov_ab_12=1 j=121
The above is the last bit from your log. Note the values of end_index and J, 121
Your logic is flawed somehow, and since I can't follow it, I can't say how.
What do you have and what do you want? It would likely be easier to use SAS dates and date calculations instead of what you're trying here.
Spoilerpriya1286 wrote:
Thanks Reeza!
Here is the full log:
ERROR: Array subscript out of range at line 1521 column 8.
bene_id=eeeeee119EAh1rJ srvc_dt=12/22/2015 end_dt=01/20/2016 dayssply=30 drg_name=slz BUYIN01=
BUYIN02= BUYIN03= BUYIN04= BUYIN05= BUYIN06= BUYIN07= BUYIN08= BUYIN09= BUYIN10=
BUYIN11= BUYIN12= HMOIND01= HMOIND02= HMOIND03= HMOIND04= HMOIND05= HMOIND06= HMOIND07=
HMOIND08= HMOIND09= HMOIND10= HMOIND11= HMOIND12= CNTRCT01= CNTRCT02= CNTRCT03= CNTRCT04=
CNTRCT05= CNTRCT06= CNTRCT07= CNTRCT08= CNTRCT09= CNTRCT10= CNTRCT11= CNTRCT12= buyin13=
buyin14= buyin15= buyin16= buyin17= buyin18= buyin19= buyin20= buyin21= buyin22=
buyin23= buyin24= hmoind13= hmoind14= hmoind15= hmoind16= hmoind17= hmoind18= hmoind19=
hmoind20= hmoind21= hmoind22= hmoind23= hmoind24= cntrct13= cntrct14= cntrct15= cntrct16=
cntrct17= cntrct18= cntrct19= cntrct20= cntrct21= cntrct22= cntrct23= cntrct24= buyin25=
buyin26= buyin27= buyin28= buyin29= buyin30= buyin31= buyin32= buyin33= buyin34=
buyin35= buyin36= hmoind25= hmoind26= hmoind27= hmoind28= hmoind29= hmoind30= hmoind31=
hmoind32= hmoind33= hmoind34= hmoind35= hmoind36= cntrct25= cntrct26= cntrct27= cntrct28=
cntrct29= cntrct30= cntrct31= cntrct32= cntrct33= cntrct34= cntrct35= cntrct36= buyin97=C
buyin98=C buyin99=C buyin100=C buyin101=C buyin102=C buyin103=C buyin104=C buyin105=C buyin106=C
buyin107=C buyin108=C hmoind97=0 hmoind98=0 hmoind99=0 hmoind100=0 hmoind101=0 hmoind102=0
hmoind103=0 hmoind104=0 hmoind105=0 hmoind106=0 hmoind107=0 hmoind108=0 cntrct97=S5921
cntrct98=S5921 cntrct99=S5921 cntrct100=S5921 cntrct101=S5921 cntrct102=S5921 cntrct103=S5921
cntrct104=S5921 cntrct105=S5921 cntrct106=S5921 cntrct107=S5921 cntrct108=S5921 buyin109=C
buyin110=C buyin111=C buyin112=C buyin113=C buyin114=C buyin115=C buyin116=C buyin117=C buyin118=C
buyin119=C buyin120=C hmoind109=0 hmoind110=0 hmoind111=0 hmoind112=0 hmoind113=0 hmoind114=0
hmoind115=0 hmoind116=0 hmoind117=0 hmoind118=0 hmoind119=0 hmoind120=0 cntrct109=S5921
cntrct110=S5921 cntrct111=S5921 cntrct112=S5921 cntrct113=S5921 cntrct114=S5921 cntrct115=S5921
cntrct116=S5921 cntrct117=S5921 cntrct118=S5921 cntrct119=S5921 cntrct120=S5921 buyin37=
buyin38= buyin39= buyin40= buyin41= buyin42= buyin43= buyin44= buyin45= buyin46=
buyin47= buyin48= hmoind37= hmoind38= hmoind39= hmoind40= hmoind41= hmoind42= hmoind43=
hmoind44= hmoind45= hmoind46= hmoind47= hmoind48= buyin49= buyin50= buyin51= buyin52=
buyin53= buyin54= buyin55= buyin56= buyin57= buyin58= buyin59= buyin60= hmoind49=
hmoind50= hmoind51= hmoind52= hmoind53= hmoind54= hmoind55= hmoind56= hmoind57= hmoind58=
hmoind59= hmoind60= buyin61= buyin62= buyin63= buyin64= buyin65= buyin66= buyin67=
buyin68= buyin69= buyin70= buyin71= buyin72= hmoind61= hmoind62= hmoind63= hmoind64=
hmoind65= hmoind66= hmoind67= hmoind68= hmoind69= hmoind70= hmoind71= hmoind72= buyin73=
buyin74= buyin75= buyin76= buyin77= buyin78= buyin79= buyin80= buyin81= buyin82=
buyin83= buyin84= hmoind73= hmoind74= hmoind75= hmoind76= hmoind77= hmoind78= hmoind79=
hmoind80= hmoind81= hmoind82= hmoind83= hmoind84= buyin85=0 buyin86=0 buyin87=0 buyin88=0
buyin89=0 buyin90=0 buyin91=C buyin92=C buyin93=C buyin94=C buyin95=C buyin96=C hmoind85=0
hmoind86=0 hmoind87=0 hmoind88=0 hmoind89=0 hmoind90=0 hmoind91=0 hmoind92=0 hmoind93=0 hmoind94=0
hmoind95=0 hmoind96=0 cntrct37= cntrct38= cntrct39= cntrct40= cntrct41= cntrct42= cntrct43=
cntrct44= cntrct45= cntrct46= cntrct47= cntrct48= cntrct49= cntrct50= cntrct51= cntrct52=
cntrct53= cntrct54= cntrct55= cntrct56= cntrct57= cntrct58= cntrct59= cntrct60= cntrct61=
cntrct62= cntrct63= cntrct64= cntrct65= cntrct66= cntrct67= cntrct68= cntrct69= cntrct70=
cntrct71= cntrct72= cntrct73= cntrct74= cntrct75= cntrct76= cntrct77= cntrct78= cntrct79=
cntrct80= cntrct81= cntrct82= cntrct83= cntrct84= cntrct85=0 cntrct86=0 cntrct87=0 cntrct88=0
cntrct89=0 cntrct90=0 cntrct91=N cntrct92=N cntrct93=N cntrct94=X0001 cntrct95=X0001
cntrct96=S5921 count=3 end_f=01/02/2016 drug_index=120 end_index=121 cov_ab_12=1 j=121 cov_d_12=.
_ERROR_=1 _N_=37
The drug_index and end_index variables weren't supposed to to act as dates. They are calculated as numbers to indicate the nth day when the drug was taken. What is confusing is that I didn't get this error when I did "do j = (drug_index - g) to end_index.
Your line
end_f = srvc_dt+11;
is incrementing the date by 11 days. I think you intend 11 months from usage.
Also andy service date prior to 1/1/2007 would have the starting J index value (drug_index-12) as 0 or smaller; 1/1/2017 would have the value > 120.
Having an uncommented magic number like 2006 in your code can lead to maintenance issues. Such as did this code run previously where the data only consisted of values from 2007 to 2016 but now needs an adjustment to handle 2017 (as possibly a start of a different year?)
has it worked?
end_f = srvc_dt+365;
What about leap years?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: