DATA Step, Macro, Functions and more

QUOTE function argument 2

Reply
Respected Advisor
Posts: 3,799

QUOTE function argument 2

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="
Respected Advisor
Posts: 4,920

Re: QUOTE function argument 2

Posted in reply to data_null__

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
Super User
Super User
Posts: 7,043

Re: QUOTE function argument 2

Posted in reply to data_null__

Seems to work in 9.3 and 9.4.

How did you find it?

Respected Advisor
Posts: 3,799

Re: QUOTE function argument 2

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.

Super User
Super User
Posts: 7,043

Re: QUOTE function argument 2

Posted in reply to data_null__

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.

Respected Advisor
Posts: 3,799

Re: QUOTE function argument 2

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'"

Super User
Super User
Posts: 7,043

Re: QUOTE function argument 2

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.

Valued Guide
Posts: 2,177

Re: QUOTE function argument 2

Posted in reply to data_null__

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"

Respected Advisor
Posts: 3,799

Re: QUOTE function argument 2

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

Valued Guide
Posts: 2,177

Re: QUOTE function argument 2

Posted in reply to data_null__

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.

Respected Advisor
Posts: 3,799

Re: QUOTE function argument 2

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)

Valued Guide
Posts: 2,177

Re: QUOTE function argument 2

Posted in reply to data_null__

Interesting about dictionary.functions

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

Ask a Question
Discussion stats
  • 11 replies
  • 356 views
  • 1 like
  • 4 in conversation