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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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