DATA Step, Macro, Functions and more

COMPRESS versus DEQUOTE

Reply
Valued Guide
Posts: 2,177

COMPRESS versus DEQUOTE

this question occurred to me when reading the following, quoted from "Problem Note 40031: Single quotation marks have been added to internal macros in SAS® Enterprise Guide®" at http://support.sas.com/kb/40/031.html
" ....... for example, &_clientapp resolves to 'SAS Enterprise Guide', but, in earlier versions, the same macro variable resolves to SAS Enterprise Guide.

To remove the quotation marks, use %SYSFUNC, for example:

title "%sysfunc(compress(&_clientapp,%str(%')))".


This solution is provided as an example, but would you like to comment on the more general application of [pre] %sysfunc(compress(&_some_macro_var_,%str(%')))[/pre] compared with this alternative[pre] %sysfunc(dequote(&_some_macro_var_))[/pre] ??

well we are a discussion forum ;-)

peterC
Respected Advisor
Posts: 3,799

Re: COMPRESS versus DEQUOTE

A subtle difference occurs if the first character of the value that is operated on by DEQUOTE is not a quote then the function does not remove any quotes. Admittedly you have to work pretty hard to make that happen.

The advantage of DEQUOTE is that is properly handles imbedded quotes and works equally well for single and double quotes. Plus with DEQUOTE you don't have to remember how to used unmatched quotes [pre]%STR(%')[/pre]
I'm not familiary with the "EG 12" but I expected either method would return the correct DEQUOTED value.



[pre]
378 data _null_;
379 infile cards eof=eof;
380 input m $char40.;
381 call symput(cats('M',_n_),m);
382 list;
383 return;
384 eof:
385 call symputX('M0',_n_-1);
386 stop;
387 cards;

RULE: ----+----1----+----2----+----3----+----4
388 'SAS Enterprise Guide'
389 'SAS Enterprise Guide'
390 'SAS Enterprise''s Guide'
391 "SAS Enterprise's Guide"
392 "SAS Enterprise's Guide"

393 ;;;;
394 run;
395 %macro p;
396 %do i = 1 %to &m0;
397 %put NOTE: \&&M&I\;
398 %put NOTE- \%qsysfunc(compress(%bquote(&&m&i),%str(%')))\;
399 %put NOTE- \%qsysfunc(dequote(%bquote(&&m&i)))\;
400 %end;
401 %mend p;
402 %p
NOTE: \'SAS Enterprise Guide' \
\SAS Enterprise Guide \
\SAS Enterprise Guide\
NOTE: \ 'SAS Enterprise Guide' \
\ SAS Enterprise Guide \
\ 'SAS Enterprise Guide' \
NOTE: \'SAS Enterprise''s Guide' \
\SAS Enterprises Guide \
\SAS Enterprise's Guide\
NOTE: \"SAS Enterprise's Guide" \
\"SAS Enterprises Guide" \
\SAS Enterprise's Guide\
NOTE: \ "SAS Enterprise's Guide" \
\ "SAS Enterprises Guide" \
\ "SAS Enterprise's Guide" \
[/pre]
Valued Guide
Posts: 2,177

Re: COMPRESS versus DEQUOTE

Posted in reply to data_null__
bemused by %put NOTE- effect! [pre] %put NOTE- ...........[/pre] not printing NOTE in the log.
Is there an explanation of this functionality anywhere?
Respected Advisor
Posts: 3,799

Re: COMPRESS versus DEQUOTE

From documentation for %PUT

The %PUT statement displays text in different colors to generate messages that look like ERROR, NOTE, and WARNING messages generated by SAS. To display text in different colors, the first word in the %PUT statement must be ERROR, NOTE, or WARNING, followed immediately by a colon or a hyphen. You may also use the national-language equivalents of these words. When you use a hyphen, the ERROR, NOTE, or WARNING word is blanked out.

Works for "regular" put and putlog too.
Valued Guide
Posts: 2,177

Re: COMPRESS versus DEQUOTE

Posted in reply to data_null__
pardon me, I should have done a better job of ... rtfm
Ask a Question
Discussion stats
  • 4 replies
  • 667 views
  • 1 like
  • 2 in conversation