Pages

Tuesday, February 25, 2014

Widgets

How to retrieve the first character of a variable in SAS

If you need to create a variable which has only first character of the character variable, then there are 4 different ways with which you can do the same in SAS. Below each variable B1,B2,B3 and B4 contains Letter A, but the length is not the same for all the four variables.


data test;
 name='Alpha';
 B1 = substr(name,1,1);
 B2 = first(name);
 substr(B3,1,1) = name;
 length B4 $1;
 B4 = name; 
run;

No comments:

Post a Comment