BookmarkSubscribeRSS Feed
Discaboota
Obsidian | Level 7
DATA CYCLE15_ALLOCATION_&PREVMNTH._&MNTH.2(WHERE=(ALLOCATION_DATE NE .) KEEP=ACCOUNT_NO BILLING_CYCLE_DAY ALLOCATION_DATE TAGGING OPENING_DPD);
SET MASTER_DPD_DUELIST_&PREVMNTH._&MNTH.(WHERE=(BKT NOT IN ('WOFF','NPA','NPA_A')) KEEP= ACCOUNT_NO BILLING_CYCLE_DAY BKT
dpd_01SEP24 -- DPD_18SEP24);
FORMAT ALLOCATION_DATE DATE7. TAGGING $CHAR25.;
ARRAY Q[*] _NUMERIC_;
IF 61 IN Q AND 31 NOT IN Q AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(61,OF Q[*])]),5),DATE7.);OPENING_DPD = 61;TAGGING = 'BUCKET 2 NON NPA';END;
IF ((61 IN Q AND 32 IN Q) OR (31 IN Q)) AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(31,OF Q[*])]),5),DATE7.);OPENING_DPD = 31;TAGGING = 'BUCKET 1 NON NPA';END;
IF 1 IN Q AND 61 NOT IN Q AND 31 NOT IN Q  AND BILLING_CYCLE_DAY = 15 THEN DO;ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(1,OF Q[*])]),5),DATE7.);OPENING_DPD = 1;TAGGING = 'BUCKET X NON NPA';END;
RUN;

Hi,

I tried to create an array, When I tried to execute it,

there was an error: 

ERROR: Array subscript out of range at line 101 column 128.
I want to put the conditions in array Q, how can I resolve this issue? 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

When you get errors, we need to see the log. We need to see the entire log for this DATA step, including the code as it appears in the log, and any ERROR/WARNING/NOTEs that appear for this DATA step, not selected parts of the log for this DATA step. Please use the </> icon, copy the log as text and paste it into the window that appears when you click on the </> icon

PaigeMiller_0-1663012019648.png

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hi @Discaboota,

 

The error message referring to "column 128" indicates that the array reference in the second IF-THEN statement is the culprit because that is the position of the first "Q" in "Q[WHICHN(31,OF Q[*])]". And this is indeed the odd one among the three similar statements: The IF condition

((61 IN Q AND 32 IN Q) OR (31 IN Q)) AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15

does not imply 31 in Q. But if 31 is not in Q, the above mentioned call to the WHICHN function returns 0 and the resulting array reference Q[0] causes the error message.

 

So you'll need to add programming logic for the case

((61 IN Q AND 32 IN Q) AND NOT (31 IN Q)) AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15
maguiremq
SAS Super FREQ

If you are able to in the future, do you mind formatting the code? It would certainly help debugging. I went ahead and did it just to see.

 

DATA CYCLE15_ALLOCATION_&PREVMNTH._&MNTH.2 (
    WHERE=(ALLOCATION_DATE NE .) 
    KEEP=ACCOUNT_NO BILLING_CYCLE_DAY ALLOCATION_DATE TAGGING OPENING_DPD
  );
  SET MASTER_DPD_DUELIST_&PREVMNTH._&MNTH. (
      WHERE=(BKT NOT IN ('WOFF','NPA','NPA_A'))
      KEEP= ACCOUNT_NO BILLING_CYCLE_DAY BKT dpd_01SEP24 -- DPD_18SEP24
  );
FORMAT ALLOCATION_DATE DATE7. TAGGING $CHAR25.;
ARRAY Q[*] _NUMERIC_;
IF 61 IN Q AND 31 NOT IN Q AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;
  ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(61,OF Q[*])]),5),DATE7.);
  OPENING_DPD = 61;
  TAGGING = 'BUCKET 2 NON NPA';
END;
IF ((61 IN Q AND 32 IN Q) OR (31 IN Q)) AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;
  ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(31,OF Q[*])]),5),DATE7.);
  OPENING_DPD = 31;
  TAGGING = 'BUCKET 1 NON NPA';
END;
IF 1 IN Q AND 61 NOT IN Q AND 31 NOT IN Q  AND BILLING_CYCLE_DAY = 15 THEN DO;
  ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(1,OF Q[*])]),5),DATE7.);
  OPENING_DPD = 1;
  TAGGING = 'BUCKET X NON NPA';
END;
RUN;
ballardw
Super User

Awful ugly code.

 

I am going to go out on a limb and after reformatting part of that code to:

 

IF 61 IN Q AND 31 NOT IN Q AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;
   ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(61,OF Q[*])]),5),DATE7.);
   OPENING_DPD = 61;
   TAGGING = 'BUCKET 2 NON NPA';
END;
IF ((61 IN Q AND 32 IN Q) OR (31 IN Q)) AND 1 NOT IN Q AND BILLING_CYCLE_DAY = 15 THEN DO;
   ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(31,OF Q[*])]),5),DATE7.);
   OPENING_DPD = 31;
   TAGGING = 'BUCKET 1 NON NPA';
END;
IF 1 IN Q AND 61 NOT IN Q AND 31 NOT IN Q  AND BILLING_CYCLE_DAY = 15 THEN DO;
   ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(1,OF Q[*])]),5),DATE7.);
   OPENING_DPD = 1;
   TAGGING = 'BUCKET X NON NPA';
END;

guess that this is the line:

 

   ALLOCATION_DATE = INPUT(SUBSTR(VNAME(Q[WHICHN(31,OF Q[*])]),5),DATE7.);

The conditions that get to this line start with

((61 IN Q AND 32 IN Q) OR (31 IN Q)) 

Which means 61 and 32 may be there but there is no requirement for 31 to be there. So for some observation with that true then Whichn(31,of q(*)) is returning 0, which would be the specific subscript that is out of range.

 

One really hopes your code doesn't look at posted in the question or you will be wasting lots of time trying to decipher "line number" in general because you have places several statements on one line making the diagnostics much less useful.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 604 views
  • 0 likes
  • 5 in conversation