Trouble with SCAN and INDEX functions being used as statements within Data record loop

Reply
Occasional Contributor
Posts: 6

Trouble with SCAN and INDEX functions being used as statements within Data record loop

Hello,

I read this post. I have a similar issue. Could you please review and let me know the proper syntax for this operation.

DATA PASS_STR FAIL_STR;

SET PREVDATA;                                 

MATCH='Y';                                           

ARRAY ASTR(*) _CHARACTER_;                           

CW=COUNTW(ACTIVE_ING,';');                    

DO C=1 TO CW BY 1 WHILE(MATCH='Y');                 

   ASTR=SCAN(ACTIVE_ING,C,';');

   F=INDEX(STRENGTH,TRIM(ASTR(C)));                  

   IF F=0 THEN MATCH='N';

PUT C CW F MATCH ASTR(C) STRENGTH;                   

END;                                                 

   IF MATCH='Y' THEN OUTPUT PASS_STR;                 

   IF MATCH='N' THEN OUTPUT FAIL_STR;                 

The result I get is the following. As you can see as soon as the program starts reading the second array component it fails to find the ASTR(2).

1 4 15 Y   1.23      1.25MG;1.25MG;1.23MG;1.25MG       

2 4 0 N    1.25       1.25MG;1.25MG;1.23MG;1.25MG        

1 4 1 Y    1.875     1.875MG;1.875MG;1.875MG;1.875MG   

2 4 0 N    1.875     1.875MG;1.875MG;1.875MG;1.875MG   

1 4 1 Y     2.5        2.5MG;2.5MG;2.5MG;2.5MG             

2 4 0 N     2.5        2.5MG;2.5MG;2.5MG;2.5MG          

When I take the SCAN process outside of the above DO loop and run it in its own DO loop I am not able to populate beyond ASTR(2).  I get zero values for ASTR(3) and ASTR(4) values

DO C=1 TO CW BY 1;                           

ASTR(C)=SCAN(ACTIVE_STRENGTH,C,';');

END;                                         

Can you please review the situation above and assist.

Occasional Contributor
Posts: 6

Re: Trouble with SCAN and INDEX functions being used as statements within Data record loop

My colleague found the solution to the above issue.

STRIP Function is to be used instead of TRIM. STRIP function removes both leading and trailing blanks. While trim only removes trailing blanks.

So the Syntax used was

   F=INDEX(STRIP(STRENGTH),STRIP(ASTR));

OR

F=FIND(STRIP(STRENGTH),STRIP(ASTR));

Also, there was no need for using Arrays. I could loop the record using the DO LOOP as I originally planned.

Ask a Question
Discussion stats
  • 1 reply
  • 146 views
  • 0 likes
  • 1 in conversation