DATA Step, Macro, Functions and more

substr with variable series/substr with arrays

Reply
N/A
Posts: 0

substr with variable series/substr with arrays

Can I use a variable series (eg blah1-blah24) in a substr statement?
For example:
data x; set y;
substr (blah1-blah24, 1, 3) = '555' then ...

Alternately, can I create new variable series using substr then use the new variable series in an array to look for the specified value throughout the variable series?

Thank you in advance for any assistance.
Sincerely, melsop
Super User
Posts: 5,431

Re: substr with variable series/substr with arrays

Posted in reply to deleted_user
What does your if substr() mean? Do you want to apply AND or OR logic between the values in the series?

I don't know of a way to do this in a single statement.
My suggestion is to create a new array coupled with a variable series, then loop through both arrays assigning values to the new array. Or, you could couple the existing variable series to an array which would make it unnecessary to assign new values, just do the if thing.

/Linus
Data never sleeps
Valued Guide
Posts: 2,177

Re: substr with variable series/substr with arrays

Posted in reply to deleted_user
use an ARRAY statement to define the list of character variables. One of the CATx functions could return the entire array as a single string. The FIND function can do the searching.
The CAT can appear within the FIND like
found = find( cat( of arrayname(*)), '555' ) ;
Using the array statement allows unrelated columns to be concatenated.
If you only want a numbered range of variables, then you don't need the array statement and the code reduces to
found = find( cat( of blah1 - blah24), '555');

it isn't SUBSTR but I think CAT and FIND do what your message seemed to want.

good luck
PeterC
Ask a Question
Discussion stats
  • 2 replies
  • 121 views
  • 0 likes
  • 3 in conversation