Pages

Wednesday, August 7, 2013

Widgets

Extract the first letter of the character variable

Have you ever needed to create a variable which is the first letter of the character variable?  In the below example there are four ways to do that. X1, X2, X3 and X4 all contain letter P.

data one;
 name='Post';
 X1 = substr(name,1,1);
 X2 = first(name);
 substr(X3,1,1) = name;
 length X4 $1;
 X4 = name; 
run;

No comments:

Post a Comment