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
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';
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.
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';
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.
thank you, You are so knowledge on SAS.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.