DATA Step, Macro, Functions and more

COMPRESS( X, "'") vs. COMPRESS(X, """).

Posts: 0

COMPRESS( X, "'") vs. COMPRESS(X, """).

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


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

And what about X="A' and X='A"?
Super Contributor
Super Contributor
Posts: 3,174

Re: COMPRESS( X, "'") vs. COMPRESS(X, """).

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. ;

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 647

Re: COMPRESS( X, "'") vs. COMPRESS(X, """).

In your example:
And what about X="A' and X='A"?
This will throw an error.Unbalanced quotes,
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation