Solved

Syntax for begins with in SAS

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2008 R2 - stored prodecure with execution plan make faster 24 125
Working with SharePoint Data 8 61
use lov values 2 61
Exchange 2013 tmp files 3 41
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

856 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