/* */

SASTechies

Place to learn SAS and enhance your professional career...

In SAS, Inorder to identify SAS Variables starting with an alphabet one can use the colon modifiers (i.e. =: 'Alphabet', >: 'Alphabet' and <: 'Alphabet') to test for character strings prefixed with the alphabet.

For example...

/*Eg. 3 records starting with J for char variable a1*/

data example;
length a1 a2 a3 a4 $ 10;
input a1 a2 a3 a4;
cards;
Johnson Ketan Mike Kites
John Sawyer Sharon Michael
Joe Kitten Sue Lula
Sharon Michael SAS Doug
Pamela Tiger Woods Peyton
;

run;

In a Data step...
/* We can use the : to identify obs for which a1 starts with J */

data finder1;
set example;
if a1=:'J'; /*keep obs whose a1 values start with J*/
run;


In a Proc step...

proc print data=example;
var a:; /*display variables that start with 'a' i.e. a1,a2,a3,a4*/
where a1=:'J';/*keep obs whose a1 values start with J*/


In a SQL step...

However in SQL, the datastep colon modifiers (i.e. =: 'Alphabet', >: 'Alphabet' and <: 'Alphabet')  do not work....But fortunately SAS provided string comparison operators as below to achieve similar tasks...

Truncated string comparison operators are used to compare two strings. They differ from conventional comparison operators in that, before executing the comparison, PROC SQL truncates the longer string to be the same length as the shorter string. The truncation is performed internally; neither operand is permanently changed. The following table lists the truncated comparison operators:

Truncated String Comparison Operators
Symbol
Definition
Example
EQT
equal to truncated strings
where Name eqt 'Aust';
GTT
greater than truncated strings
where Name gtt 'Bah';
LTT
less than truncated strings
where Name ltt 'An';
GET
greater than or equal to truncated strings
where Country get 'United A';
LET
less than or equal to truncated strings
where Lastname let 'Smith';
NET
not equal to truncated strings
where Style net 'TWO';

/* The same as above but with eqt comparison operators */

proc sql;
create table finder2 as
select * from example
where a1 eqt 'J'; /*keep obs whose a1 values start with J*/
quit;



Reference
http://support.sas.com/onlinedoc/913/getDoc/en/sqlproc.hlp/a001334118.htm

0 comments:

Post a Comment





Technology Top Blogs Programming Blogs - BlogCatalog Blog Directory TopOfBlogs Blog Directory blogarama - the blog directory blog search directory Blog Directory - OnToplist.com hihera.com On our way to 1,000,000 rss feeds - millionrss.com Increase Page Rank