BookmarkSubscribeRSS Feed
🔒 This topic is locked. We are no longer accepting replies to this topic. Need further help? Please sign in and ask a new question.
SAS_Tipster
Moderator

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
Ksharp
Super User

One more function CHAR().

data one;
    name='Fred';
    a1 = char(name,1);
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Visit a random SAS tip This SAS Tips board is not open for replies or comments, but we welcome your feedback and questions. Have a question or comment about this tip? Start a new topic in one of our discussion boards, and reference this tip topic.
Discussion stats
  • 1 reply
  • 11014 views
  • 3 likes
  • 2 in conversation