| Date: | Sat, 27 Dec 2008 00:27:52 -0800 |
| Reply-To: | RolandRB <rolandberry@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | RolandRB <rolandberry@HOTMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: Need help with %qscan and %scan |
|
| Content-Type: | text/plain; charset=ISO-8859-1 |
On Dec 25, 8:44 pm, Tony <tony...@gmail.com> wrote:
> Hi All,
>
> I had the following codes and there were running errors. The macro
> variables GRP1 and GRP2 were correctly resolved. However, I got this
> error 200 from the proc sql statement. After I change the %qscan to
> %scan, it worked! I thought I should use %qscan to mask the "-" in the
> macro variable OABYGROUP. How come it only works with %scan?
>
> Thanks in advance.
> Tony
>
> Error Message:
>
> 1 proc sql; select count(*) from a where &GRP1; quit;
> -
> 200
> ERROR 200-322: The symbol is not recognized and will be ignored.
>
> SAS Codes:
>
> options nocenter formdlim=' ' nodate nonumber symbolgen mlogic;
> options obs=0;
>
> %let OABYGROUP=%str(CAT="ACTIVES-SSG" CAT="ACTIVES-DC");
> data a;
> CAT="ACTIVES-SSG";
> mem_no="ABCDEFG";
> run;
>
> %macro a;
> %local g;
> %let g=1;
> %do %while(%length(%qscan(&OAbygroup,&g,%str( ))) GT 0);
> %let GRP&g=%qscan(&OAbygroup,&g,%str( ));
> %put &&GRP&g;
> %let g=%eval(&g + 1);
> %end;
> %let g=%eval(&g -1);
> %put &GRP1;
> %put &GRP2;
> proc sql;
> select count(*) from a where &GRP1;;
> quit;
> %mend;
> %a;
The "%q" macro functions "macro quote" the result. This "macro
quoting" works fine all times I can think of within macro code itself
but this macro quoting is not understood and not valid in ordinary sas
code. You always have the option of undoing what you have macro quoted
by using %unquote() so where you must use the "%q" macro functions
then %unquote() the result for the benefit of your ordinary sas code
when you include the macro string.
|