Solved

Syntax for begins with in SAS

Posted on 2011-09-09
1
883 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now