BookmarkSubscribeRSS Feed
Raju_SAS_User
Calcite | Level 5

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.

1 REPLY 1
Raju_SAS_User
Calcite | Level 5

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.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 382 views
  • 0 likes
  • 1 in conversation