BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MK_96
Fluorite | Level 6
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;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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;



 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please explain further. What is the desired output from "extract Y values"?

 

Please do not type in all capitals.

--
Paige Miller
MK_96
Fluorite | Level 6
Only y values should be in new variable
Reeza
Super User
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;



 

ballardw
Super User

@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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 836 views
  • 2 likes
  • 4 in conversation