BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Can any experienced SAS-programmer confirm that

Y1=COMPRESS( X, "'" ) and Y2=COMPRESS(X, """ ) will give the same result whether or not the character in X is surrounded by single or double quotation remarks?

I clarify: In first expression: " ' ". In the second expression: " " "

I.E., is it true that

if X='A' then Y1=A and Y2=A

and

if X="A" then Y1=A and Y2=A

And what about X="A' and X='A"?
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you try the logic to determine the SAS behavior. For consideration, your Y2 assignment statement is improperly coded, where you are using the same character as the delimiter *AND* also in your constant string -- so you must have two consecutive double-quote marks. As you have coded the Y2 assignment statement, SAS will eventually issue an diagnostic message about unbalanced quotation marks or something similar.

Also, your "I.E. " reference to A is as a SAS variable and not a constant -- you have never declared a SAS variable named A (neither character or SAS-default numeric).

Suggest you heavy-up on reading DOC about COMPRESS function and take SAS DATA step processing for a ride -- use some PUTLOG _ALL_; commands and some addditional conditional diagnostic statements, such as:

* you fill in expression below, as needed. ;
IF THEN PUTLOG "YEP";
ELSE PUTLOG "NOPE";

Scott Barry
SBBWorks, Inc.
SASPhile
Quartz | Level 8
In your example:
And what about X="A' and X='A"?
This will throw an error.Unbalanced quotes,

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1265 views
  • 0 likes
  • 3 in conversation