Solved

Syntax for begins with in SAS

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

717 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