Working With Character Functions..!!!

                                        In this post we will see character strings, take strings apart and put them back together again, and remove selected characters from a string. We can remove classes of characters, such as digits, punctuation marks, or space characters and even we can match between the two characters. Lets see this by some examples.

#Problem:

                                 Using the data set Mixed, we want to the create following new variables:
a. NameLow – Name in lowercase
b. NameProp – Name in proper case
c. NameHard – Name in proper case without using the PROPCASE function

#Data set:

data A15028.A28_mixed;
   input Name & $20. ID;
datalines;
Daniel Fields  123
Patrice Helms  233
Thomas chien  998
;
Proc print data=A15028.A28_mixed;
run;

#Solution:

data A15028.A28_mixed1;
set A15028.A28_mixed;
length First Last $ 15 NameHard $ 20;
NameLow = lowcase(Name);
NameProp = propcase(Name);
First = lowcase(scan(Name,1,' '));
Last = lowcase(scan(Name,2,' '));
substr(First,1,1) = upcase(substr(First,1,1));
substr(Last,1,1) = upcase(substr(Last,1,1));
NameHard = catx(' ',First,Last);
drop First Last;
run;

#Output:


# Learning:

                            In this program we learned two new SAS functions called lowcase and Propcase. Also we used the substr function and how to use them in the SAS program.





No comments:

Post a Comment