How to use Truncated String Comparison Operators In Proc SQL?

The dataset can use the Truncated String Comparison Operators (such as =:, >:, and <=:) for truncated string comparisons. However, you find that the Colon operator is not available in PROC SQL.

In Proc SQL, you can use the Truncated String Operators such as EQT, GTT, LTT, GET, LET and NET.

The truncated string comparison operator is used to compare two strings. The difference between PROC SQL and conventional comparison operators is that it trims the longer string to the same length as the shorter string before executing the comparison.

Both operands remain unchanged when the truncation is performed internally. The following table lists the truncated 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’;
Truncated String Comparison Operators

The following example returns a list of Countries that have 'CO' at the beginning of their names:

proc sql;
Title "List of countries beginning with the characters'CO'";
	select Name from sashelp.demographics where Name eqt 'CO';
quit;

Output:

How to use Truncated String Comparison Operators In Proc SQL?
Truncated String Comparison Operators

The following example returns a list of countries that have 'U' to ‘Z‘ at the beginning of their names:

proc sql;
Title 'List of countries beginning with the letter 'U' and later';
	select Name from sashelp.demographics where Name get 'U';
quit;

Output:

How to use Truncated String Comparison Operators In Proc SQL?
Truncated String Comparison Operators

So, this was our side on Truncated String Comparison Operators In Proc SQL. We hope that you must have found it helpful.

Moreover, suggest suggestions in the comment section below if you have other suggestions. We will take those lists in our further blog post.

Thanks for reading!

Do you have any tips to add? Let us know in the comments.

Please subscribe to our mailing list for weekly updates. You can also find us on Instagram and Facebook.

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.