new ba
new ba

Reputation: 1

sas cleaning using if then statements

I am trying to clean my data for language but when I print it is not cleaned. I have placed this under my set statement

here is my code:

if lang in ("spanish, Engglishish, ssanklish, England) then lang="English";
run;

Upvotes: 0

Views: 23

Answers (1)

Tom
Tom

Reputation: 51581

If you only want to match a single string you can use equality operator instead of the IN operator.

if lang = "Engglish, Engglishish, Engl, England, English, Englishh, Englisj, Englsh, En, Inglish, Old, NewEnglish, Oldenglish, Onglish, english" 
  then lang="English"
;

If you want to match any of the substrings in your list then make each one its own string literal. Note that the IN operator in SAS is just as happy with spaces as commas between the items.

if lang in ("Engglish" "Engglishish" "Engl" "England" "Englishh" "Englisj" "Englsh" 
            "En" "Inglish" "Old" "NewEnglish" "Oldenglish" "Onglish" "english") 
  then lang="English"
;

Make sure to use that in a valid data step.

data want;
  set have;
  if lang in ("Engglish" "Engglishish" "Engl" "England" "Englishh" "Englisj" "Englsh" 
             "En" "Inglish" "Old" "NewEnglish" "Oldenglish" "Onglish" "english") 
    then lang="English"
  ;
run;

Do you really want to change Old to English?

Upvotes: 1

Related Questions