I tried to assign a new value to match with another value by group.
If I use the code below, it came out all "AFC-WEST'.
Conference = propcase(Team);
Retain Conference;
if Team = 'Ravens to Viking then Conference = 'AFC-NORTH';
else Conference = 'AFC-WEST;
The result should look at below.
Team | Conference |
Campbell | AFC-North |
NorthRaleigh | AFC-North |
Batter | AFC-North |
Creek | AFC-North |
South | AFC-West |
Miami | AFC-West |
Bellfort | AFC-West |
Viking | AFC-South |
Chief | AFC-South |
what do you mean by the if statement
Conference = propcase(Team);
Retain Conference;
if Team = 'Ravens to Viking then Conference = 'AFC-NORTH';?/*for one, it is syntactically incorrect and 2. are you trying a range from Ravens--Viking*/
else Conference = 'AFC-WEST;
Team | Conference |
Campbell | AFC-North |
NorthRaleigh | AFC-North |
Batter | AFC-North |
Creek | AFC-North |
South | AFC-West |
Miami | AFC-West |
Bellfort | AFC-West |
Viking | AFC-South |
Chief | AFC-South |
If team = 'Batter tp Creek' then Conference = 'AFC-NORTH';
I was trying to do the matching. Batter and Creek are the value at Team column so it is Batter and CreeK. SAS will assign AFC-NORTH to these value.
I really have no idea how to match.
When you have many character values to compare one way is to use the IN operator but you need to list every value you are looking for:
if team in ('Ravens' 'Otherteamname' 'Vikings') then ...
aah ok,
are you trying to do this?
Conference = propcase(Team);
Retain Conference;
if Team =in ('Ravens' ,' Viking') then Conference = 'AFC-NORTH';
else Conference = 'AFC-WEST;
Yes, I changed it to
if team in ('Campbell','Batter') then Conference = 'AFC-NORTH';
else Conference = 'AFC-WEST';
It still the entire column are AFC-WEST.
And, if I have more than two value to be matched.
Is it a faster way to match them?
Try proc format, load your look up values in proc format and apply in a datastep
easy to maintain and edit
@elsalam wrote:
Yes, I changed it to
if team in ('Campbell','Batter') then Conference = 'AFC-NORTH';
else Conference = 'AFC-WEST';
It still the entire column are AFC-WEST.
And, if I have more than two value to be matched.
Is it a faster way to match them?
Show the entire data step and any messages from log. Paste into a code box opened using the forum {I} icon to preserver formatting of code and any error or warning messages. It might also help to provide some actual values from you data as a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Note that the comparison matches the entire field. So if the value has any leading blanks or other characters than "Campbell" the match will return false or if the data is not in the same case, "campbell" is not the same as "CAMPBELL" or "Campbell" or "cAmpbell"
The list of values used in the in comparison can be more than two, I just didn't feel like typing more.
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!
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.