Solved

Syntax for begins with in SAS

Posted on 2011-09-09
1
948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Querying data from 3 SQL tables 2 45
Very Large data in MYSQL 7 95
SQL 2008 R2 2 31
populate value based on what is selected in lov 2 37
This article describes some very basic things about SQL Server filegroups.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

730 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