I have the followings,
*--FA807518F1456-FA807518F1456-1002-07-HS002193888 *--HS002108475----HS002108475 *---HS002105485---SFHS002105485 *---HS002105485---SFHS002105485 *---HS002105485---SFHS002105485 *---HS002105485---SFHS002105485 *------SFHS002106080 *------AAZKA021821TSPLOS *------AAZKA021821TSPBRK *------AAZKA030421TSPLOS *------AAZKA030421TSPBRK *------AAZKA031821TSPBRK *--HQ0642149245----HQ0642149245 *------AAZKA040121TSPLOS *------AAZKA041221TSPBRK *---HS47371659Z010---HS47371659Z010 *--HQ0642149245----HQ0642149245 *--AGENTPAGE----HS002121076MW0 *--ZKA----AA *--ZKA----AA *--AGENTGUZMAN----HS002121076MW0 *--AGENTLEE----HS002121076MW0 *--AGENTMELLGREN2----HS002121076MW0 *--AGENTPRICE----HS002121076MW0 *--PWFFSA21337860321--0007--HAFC0583142 *--AGENTELDRIDGE----HS002121076MW0 *--AGENTMELLGREN----HS002121076MW0 *------AAZKA042921TSPBRK *--N0003421----AA
I am trying to get those rows that start with HS002 or ZKA and place them in a variable called GOTIT. Some kind of substring. Thank you!
What does the "*--" mean?
Can you describe the image of the dataset you want?
I'm sorry to say that "*--HS002" does not begin with "HS002"... but is this the result you want?
Hi:
But those strings appear multiple places, as shown below. The WHERE_HS variable shows the place in the string where HS002 is found and the WHERE_ZK shows the place in the string where ZKA is found. Do you want ALL of those rows? Or are there more criteria?
Cynthia
These are all the rows that have HS002 or ZKA:
You initially listed 29 rows and 24 rows met the simple condition of having either HS002 or ZKA in the string.
@mauri0623 wrote:
I tried index but the values are coming up as numbers.
Of course they are. Index returns a position number of where the value is found and 0 when not found.
So typically if the criteria is "somevalue somewhere in the variable" then code often looks like:
If index(variable,'somevalue') > 0 then <do something>;
where the "do something" could be assign a value to a variable, delete the record, start a DO/End block of code to do something more complex.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.