Posts

Showing posts with the label Propcase Function in SAS

How to use the PROPCASE function

Using the PROPCASE function The "old" way to capitalize the first letter of words was to use LOWCASE, UPCASE, and the SUBSTR function, like this: DATA CAPITALIZE; INFORMAT FIRST LAST $30.; INPUT FIRST LAST; FIRST = LOWCASE (FIRST); LAST = LOWCASE (LAST); SUBSTR( FIRST , 1 , 1 ) = UPCASE(SUBSTR( FIRST , 1 , 1 )); SUBSTR( LAST , 1 , 1 ) = UPCASE(SUBSTR( LAST , 1 , 1 )); DATALINES; ronald cODy THomaS eDISON albert einstein ; PROC PRINT DATA=CAPITALIZE NOOBS; TITLE "Listing of Data Set CAPITALIZE"; RUN ; With the PROPCASE function in SAS 9.1, it's much easier. DATA PROPER ; INPUT NAME $60.; NAME = PROPCASE (NAME); DATALINES; ronald cODy THomaS eDISON albert einstein ; PROC PRINT DATA=PROPER NOOBS; TITLE "Listing of Data Set PROPER"; RUN; source:www.support.sas.com Example: data test ; x= lowcase ( ' MY NaMe iS SARaTh ' ) ; y= propcase (x) ; z= propcase ( lowcase ( ' ...

How to capitalize the first letter of every word in a string

Image
Capitalize the first letter of every word in a string Convert a text string into mixed case. Note: Beginning in SAS 9.1, this task is easily accomplished with the PROPCASE function. See Sample 2 on the Full Code tab. /* Sample 1: COMPBL, LOWCASE, SCAN, INDEX, UPCASE, SUBSTR */ data sample; input name $char50.; /* Lowercase the entire string, remove consecutive blanks */ newname= compbl ( lowcase (name)); length next $ 20; i=0; next=scan(newname,1, ' ' ); do while (next ne ' ' ); i+1; /* Scan off each 'word' based upon a space, locate the position */ /* of the first letter in the original string, UPCASE the first */ /* letter and use SUBSTR to replace the byte. */ pos= indexw (newname,trim(next)); substr (newname,pos,1)= upcase ( substr (newname,pos,1)); next= scan (newname,i, ' ' ); end; keep name newname; datalines; Jane DOE min ning chou HENRIK HANSSON D ETCHEVERRY, Charo B ; proc print ; run; /* Sample 2: PROPCASE (available in SAS 9.1) */...