Solved
Contributor
Posts: 25

# function

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

Accepted Solutions
Solution
‎04-26-2018 06:08 PM
Super User
Posts: 6,935

## Re: function

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';

All Replies
Super User
Posts: 24,015

## Re: function

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.

Solution
‎04-26-2018 06:08 PM
Super User
Posts: 6,935

## Re: function

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';

Super User
Posts: 13,941

## Re: function

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.

Contributor
Posts: 25

## Re: function

thank you,  You are so knowledge on SAS.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 193 views
• 0 likes
• 4 in conversation