🔒 This topic is locked.
We are no longer accepting replies to this topic. Need further help? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-05-2018 05:09 PM
(13504 views)
Have you ever needed to create a variable containing only the first character of a character variable? This DATA step shows four different ways to retrieve only the first character. Each new variable (A1, A2, A3, A4) contains only the letter 'F', however the lengths of these four variables are NOT all the same.
data one; name='Fred'; a1 = substr(name,1,1); a2 = first(name); substr(a3,1,1) = name; length a4 $1; a4 = name; run;
This tip was originally published by Art Carpenter on sasCommunity.org.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One more function CHAR().
data one;
name='Fred';
a1 = char(name,1);
run;