As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Tip of the Day:August 5

From sasCommunity
Jump to: navigation, search

sasCommunity Tip of the Day


As part of the decommissioning effort for sasCommunity.org this article/tip has been migrated to communities.sas.com.

The new home for this article/tip is August 5 (https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Retrieving-the-First-Character/m-p/475834#M179)



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;

Submitted by Art Carpenter. Contact me at my Discussion Page.



Feel free to comment on this tip.


Prior tip - Next tip - Random Tip

Submit a Tip