BookmarkSubscribeRSS Feed
data_null__
Jade | Level 19

I do not find it in the documentation.  I'm always the last to know. :smileyshocked:

data _null_;
   a =
"Fisher's";
  
do q = '''',"""";
     
x = quote(a,q);
      put x= q=;
      end;
  
run;

x='Fisher''s' q='
x="Fisher's" q="
11 REPLIES 11
PGStats
Opal | Level 21

Thus it is equivalent to :

data _null_;  

a = "Fisher's";

   do q = 'A1', "A2";

      x = catq(q, a);

      put x= q=;

      end;

   run;

PG

PG
Tom
Super User Tom
Super User

Seems to work in 9.3 and 9.4.

How did you find it?

data_null__
Jade | Level 19

I found it because I was looking at the documentation for CATQ and thought why don't I try that with QUOTE. Of course it's not the same as CATQ which has the more logical 1 and 2 argument. 

We should probably use CATQ('A1' to keep from breaking the "don't use undocumented features" rule.

Tom
Super User Tom
Super User

Only trouble I have found with using CATQ is that if you want to use it with %SYSFUNC() it does not handle strings with length 0.  QUOTE() is happy to handle such strings and returns two adjacent quote charaters,  "" or '' if you use this newly discovered second argument.

data_null__
Jade | Level 19

Also this looks fishy.  But maybe I did something wrong, and there is a logical explanation that I don't get.

27         %let x=%nrstr(Fisher%'s);

28         %PUT NOTE: %sysfunc(quote(&x,%str(%')));

NOTE: 'Fisher''s'

29         %PUT NOTE: %sysfunc(catq(A1,&x));

NOTE: 'Fisher''s'''

30         %PUT NOTE: %sysfunc(catq(A2,&x));

NOTE: "Fisher's'"

Tom
Super User Tom
Super User

Another interesting note is that in SAS 8.2 and 9.2 it will accept the second argument, but it does not seem to have any effect.  It will complain if you give it more than two arguments.

Peter_C
Rhodochrosite | Level 12

no second arg is documented in SAS 9.4 (TS1M1)

BUT V.GOOD TO HAVE

I'm surprised the choice is the quoting char and not S and Q

It seems that no value other than a single single quote  will change default, double quote behaviour. ( but I only tested all 2byte values)

It might have been useful to support other quote symbols (OK I don't need it but I can't speak for others)

Perhaps it might be enhanced in that way before it is "formally announced"

data_null__
Jade | Level 19

Peter Crawford wrote:

It seems that no value other than a single single quote  will change default, double quote behaviour. ( but I only tested all 2byte values)

It might have been useful to support other quote symbols (OK I don't need it but I can't speak for others)

Seems like the "quote" character could be any character with the syntax the way it is. 

Where quote('Peter','t') produces tPettert

Peter_C
Rhodochrosite | Level 12

data_null_;

My experince "varied"

Only the s  changed quoting.

Your experience I hoped for.

to what release must I upgrade to share your experience.

data_null__
Jade | Level 19

My experience is the same as yours, I did me mean to suggest otherwise.  Only change is when the second argument is a single quote.  Must be one byte trailing blanks don't work.  I was just saying that it seems like the syntax would allow any character to be the "quote" character.

I noticed dictionary.functions shows that QUOTE as max args = 2.

My version of SAS is

NOTE: SAS (r) Proprietary Software 9.3 (TS1M2)

Peter_C
Rhodochrosite | Level 12

Interesting about dictionary.functions

You're sending me on a missionj to find differences between that and the doc (well, I'm tempted):smileymischief:

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
  • 11 replies
  • 1171 views
  • 1 like
  • 4 in conversation