BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

May I request someone to illutsrate me the following example to understand the difference between %scan and %qscan?

 

%macro a;
   aaaaaa
%mend a;
%macro b;
   bbbbbb
%mend b;
%macro c;
   cccccc
%mend c;

%let x=%nrstr(%a*%b*%c);
%put X: &x;
%put The third word in X, with SCAN: %scan(&x,3,*);
%put The third word in X, with QSCAN: %qscan(&x,3,*);


The %PUT statement writes these lines to the log: 
X: %a*%b*%c
The third word in X, with SCAN: cccccc
The third word in X, with QSCAN: %c

I took this example from http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514scan.htm

 

 

In the example citied above, I would like to understand how does %scan and %qscan function got resolved?

 

If X resolves to %a*%b*%c then scan function should return %c whereas it returns cccccc. Why so? Whether my underst

2 REPLIES 2
Kurt_Bremser
Super User

The %scan() function does not prevent the evaluation of the characters & and %. Therefore macro calls and variables are resolved before the scan for words is done.

%qscan prevents macro evaluation, as it treats & and % as "normal" characters.

Therefore you get what the macros resolve to with %scan, and the unresolved macro names with %qscan.

SAS_inquisitive
Lapis Lazuli | Level 10
%qscan is macro quoting function. 'q' is mnemonic for quoting. It treats macro triggers (&, %) as text. http://www2.sas.com/proceedings/sugi25/25/aa/25p004.pdf

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3559 views
  • 0 likes
  • 3 in conversation