Solved

Syntax for begins with in SAS

Posted on 2011-09-09
1
922 Views
Last Modified: 2013-11-16
Can someone please tell me the syntax for begins with in SAS.

ie.  I would like to select all records where code begins with "SNR".
0
Comment
Question by:morinia
1 Comment
 
LVL 7

Accepted Solution

by:
d507201 earned 250 total points
ID: 36513878
Use the substring function for this --
     if substr(varName,1,3)='SNR';

When you're looking for a character string contained anywhere in a variable, use the INDEX or FIND functions.  Find is a bit more robust because it has a switch that ignores case and also a switch that ignores trailing balnks.

if index(varname,'SNR') will identify things like ABCSNR123.
if find(varname,'SNR','i') will identify both ABCSNR123 and ABcSnR123 because it ignores case.

Here's a clever one.  Don't forget the REVERSE function.  It does just that--reverses a character string so that SNRABC123 becomes 321CBARNS.  So if you have a string that have varying length and you need to check to see if the last three characters are SNR, then you could use
     if substr(reverse(varname),1,3)='RNS

Ron Cody's book 'SAS Functions by Example' is a good investment.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question