text2 = compress(text, 'Y', 'ki');
Use COMPRESS with the modifiers, k for keep and i for ignoring case.
@MK_96 wrote:
HOW CAN I EXTRACT ONLY "Y" VALUES TO NEW VARIABLE FROM BELOW CODE .?
IS THERE ANY FUNCTION THAT WORKS ??
DATA CHK;
TEXT="122 AGH Y yy jaja Yy &#^#7aa ";
RUN;
Please explain further. What is the desired output from "extract Y values"?
Please do not type in all capitals.
text2 = compress(text, 'Y', 'ki');
Use COMPRESS with the modifiers, k for keep and i for ignoring case.
@MK_96 wrote:
HOW CAN I EXTRACT ONLY "Y" VALUES TO NEW VARIABLE FROM BELOW CODE .?
IS THERE ANY FUNCTION THAT WORKS ??
DATA CHK;
TEXT="122 AGH Y yy jaja Yy &#^#7aa ";
RUN;
@MK_96 wrote:
HOW CAN I EXTRACT ONLY "Y" VALUES TO NEW VARIABLE FROM BELOW CODE .?
IS THERE ANY FUNCTION THAT WORKS ??
DATA CHK;
TEXT="122 AGH Y yy jaja Yy &#^#7aa ";
RUN;
There are probably multiple functions that work depend on what the desired result actually is.
If you want to remove the Y, first you have tell us if that means remove the lower case y as well. I say this because you are using all capital letters so it is not clear.
Here are just some of the possible examples
DATA CHK; TEXT="122 AGH Y yy jaja Yy &#^#7aa "; text2 = compress(text,'Y'); text3 = compress(text,'y'); text4 = compress(text,'Y','i'); text5 = compress(text,'Y','ik'); text6 = translate(text,' ','Yy'); RUN;
Compress removes characters. Examples show just upper case Y, lower case Y, case insensitive Y, remove everything except the case insensitive Y's (extracted from the string and KEPT). Translate replaces characters with a different single character.
TRANWRD might be another option as well as regular expressions.
But since you did not provide an example of what you expect this is all guesses as to what you may want.
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.