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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 759 views
  • 2 likes
  • 4 in conversation