BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
elsalam
Calcite | Level 5

What kind of function can search certain character to assign a new observation name.

 

example for observation:  iFF-F  Edd-M  Ehh-f  igg-m

 

I need to assign  Total_F to the character that have F/f and Total_M to the character that have M/m.

 

I changed all character to upcase and try to use Translate but not work.

 

 

 

Thx

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

I'm going to guess that this might be what you are looking for:

 

if scan(var, -1, '-') in ('m', 'M') then var = 'Total_M';

 

if scan(var, -1, '-') in ('f', 'F') then var = 'Total_F';

View solution in original post

4 REPLIES 4
Reeza
Super User

Hi, your question is incredibly unclear. Please start off by explaining, in detail, what you have, then what you want and anything you've tried so far. If you cannot share your real data, please mock some up to replicate your issue that accurately reflects your data.

Astounding
PROC Star

I'm going to guess that this might be what you are looking for:

 

if scan(var, -1, '-') in ('m', 'M') then var = 'Total_M';

 

if scan(var, -1, '-') in ('f', 'F') then var = 'Total_F';

ballardw
Super User

Since your "examples" do not include the strings 'F/f' or 'M/m' the description is likely incomplete.

Also "assign a new observation name." is not clear as in SAS observations to not have names. A SAS observation is all of the data on a row as one way of thinking.

 

If you mean if the letter F or the letter f occurs in the value of variable then reset the entire value of that variable to "Total_F" there are some other details needed.

One is what is the length of the variable. The examples you show are all exactly 4 characters. If the length of the variable is 4 then "Total_F" would not fit because that has 7 characters.

 

TRANSLATE likely would not work as it replaces single characters with single characters.

 

Or show more explicitly the result of this operation.

elsalam
Calcite | Level 5

thank you,  You are so knowledge on SAS.

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
  • 4 replies
  • 861 views
  • 0 likes
  • 4 in conversation