BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
LinusH
Tourmaline | Level 20
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
Peter_C
Rhodochrosite | Level 12
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 626 views
  • 0 likes
  • 3 in conversation