From: toby dunn on
Yom ,

http://support.sas.com/onlinedoc/913/docMainpage.jsp
Go here and learn to use this site.

IF you would have cared to read about the qouting functions before you used
them you would have found out that %STR and %NRSTR are both compile time
quoting functions. With a few characters difference teh do the same thing
at the same time.

Odds are you want the results of %macrolist to be quoted. DO the
following:

Ask yourself the following questions:

1.) Is there anything that needs to be qouted?

If the answer is NO then dont worry with quoting at all.

If yes then grab your coolaid and follow me:

2.) When does it need to be quoted, at compile time or execution time?

If the answer is compile time you have two choices: %str and %Nrstr, read
up on them and learn teh differences between them.

If it is at execution time then you need to look at %bquote, %nrbquote,
%superQ.

3.) What needs to be quoted: commas, quotes ( single or double ), ampers,
percent signs, etc....

after you find this out then look for the right function to quote the right
character.


If I knew what you were trying to hide from the SAS processor I could help
you out a little more. As it stands right now I dont know what you are
trying to hide. Is it a quote (single or double) is it a amper or percent
sign, is it a comma, or a space? Knowing these little things will make a
difference.


Toby Dunn

When everything is coming at you all at once, your in the wrong lane.

A truly happy person is someone who can smile and enjoy the scenery on a
detour.





From: yom <yomsas(a)GMAIL.COM>
Reply-To: yom <yomsas(a)GMAIL.COM>
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Re: Check if macro parameter is empty
Date: Tue, 5 Sep 2006 16:38:16 +0200

Thank you very much for your help !
But if I use %str I get the same error.

Here is the full code :


%macro example;

%macro test(macrolist=);
%if %str(&macrolist.) ne %then %do;
%Put Not Empty!!! ;
%End ;
%Else %do ;
%Put Empty!!! ;
%End ;
%mend;

%test(macrolist=%NRSTR(%val(file=aaa)));

%mend;

%example;






2006/9/5, toby dunn <tobydunn(a)hotmail.com>:
>
>Yom ,
>
>First off your macro variable will never be empty the way you have it
>coded
>up:
>
>%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outfolder1)
>
>Is always the results. You should learn macros before you jump into using
>macro qouting. %Nrstr qoutes the value at compile time not execution time.
>
>
>%Macro Test( AAA = ) ;
>
>%If ( &AAA = ) %Then %Do ;
>%put Empty!!! ;
>%End ;
>%Else %do ;
>%Put Not Empty!!! ;
>%End ;
>%Mend ;
>
>%Test( AAA = )
>%Test( AAA = ABCD )
>
>
>
>Toby Dunn
>
>When everything is coming at you all at once, your in the wrong lane.
>
>A truly happy person is someone who can smile and enjoy the scenery on a
>detour.
>
>
>
>
>
>From: yom <yomsas(a)GMAIL.COM>
>Reply-To: yom <yomsas(a)GMAIL.COM>
>To: SAS-L(a)LISTSERV.UGA.EDU
>Subject: Check if macro parameter is empty
>Date: Tue, 5 Sep 2006 15:50:25 +0200
>
>Dear All,
>
>I have this statement :
>macrolist=%NRSTR(%mymacro1
>(file=&file1,varlist=&varlist1,outfolder=&outfolder1));
>I would like to test if macrolist is empty or not.
>If I use
>%if &macrolist. ne %then %do;
>......
>%end;
>I get this error message :
>ERROR: Required operator not found in expression: &macrolist. ne
>Please do you know what I have to add ?
>
>Thank you very much in advance !
>
>yom
>
>
>
From: yom on
Thank you very much ! Tonight I will go to bed being less stupid !

Best regards,

yom


2006/9/5, toby dunn <tobydunn(a)hotmail.com>:
>
> Yom ,
>
> http://support.sas.com/onlinedoc/913/docMainpage.jsp
> Go here and learn to use this site.
>
> IF you would have cared to read about the qouting functions before you
> used
> them you would have found out that %STR and %NRSTR are both compile time
> quoting functions. With a few characters difference teh do the same thing
> at the same time.
>
> Odds are you want the results of %macrolist to be quoted. DO the
> following:
>
> Ask yourself the following questions:
>
> 1.) Is there anything that needs to be qouted?
>
> If the answer is NO then dont worry with quoting at all.
>
> If yes then grab your coolaid and follow me:
>
> 2.) When does it need to be quoted, at compile time or execution time?
>
> If the answer is compile time you have two choices: %str and %Nrstr, read
> up on them and learn teh differences between them.
>
> If it is at execution time then you need to look at %bquote, %nrbquote,
> %superQ.
>
> 3.) What needs to be quoted: commas, quotes ( single or double ), ampers,
> percent signs, etc....
>
> after you find this out then look for the right function to quote the
> right
> character.
>
>
> If I knew what you were trying to hide from the SAS processor I could help
> you out a little more. As it stands right now I dont know what you are
> trying to hide. Is it a quote (single or double) is it a amper or percent
> sign, is it a comma, or a space? Knowing these little things will make a
> difference.
>
>
> Toby Dunn
>
> When everything is coming at you all at once, your in the wrong lane.
>
> A truly happy person is someone who can smile and enjoy the scenery on a
> detour.
>
>
>
>
>
> From: yom <yomsas(a)GMAIL.COM>
> Reply-To: yom <yomsas(a)GMAIL.COM>
> To: SAS-L(a)LISTSERV.UGA.EDU
> Subject: Re: Check if macro parameter is empty
> Date: Tue, 5 Sep 2006 16:38:16 +0200
>
> Thank you very much for your help !
> But if I use %str I get the same error.
>
> Here is the full code :
>
>
> %macro example;
>
> %macro test(macrolist=);
> %if %str(&macrolist.) ne %then %do;
> %Put Not Empty!!! ;
> %End ;
> %Else %do ;
> %Put Empty!!! ;
> %End ;
> %mend;
>
> %test(macrolist=%NRSTR(%val(file=aaa)));
>
> %mend;
>
> %example;
>
>
>
>
>
>
> 2006/9/5, toby dunn <tobydunn(a)hotmail.com>:
> >
> >Yom ,
> >
> >First off your macro variable will never be empty the way you have it
> >coded
> >up:
> >
> >%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outfolder1)
> >
> >Is always the results. You should learn macros before you jump into
> using
> >macro qouting. %Nrstr qoutes the value at compile time not execution
> time.
> >
> >
> >%Macro Test( AAA = ) ;
> >
> >%If ( &AAA = ) %Then %Do ;
> >%put Empty!!! ;
> >%End ;
> >%Else %do ;
> >%Put Not Empty!!! ;
> >%End ;
> >%Mend ;
> >
> >%Test( AAA = )
> >%Test( AAA = ABCD )
> >
> >
> >
> >Toby Dunn
> >
> >When everything is coming at you all at once, your in the wrong lane.
> >
> >A truly happy person is someone who can smile and enjoy the scenery on a
> >detour.
> >
> >
> >
> >
> >
> >From: yom <yomsas(a)GMAIL.COM>
> >Reply-To: yom <yomsas(a)GMAIL.COM>
> >To: SAS-L(a)LISTSERV.UGA.EDU
> >Subject: Check if macro parameter is empty
> >Date: Tue, 5 Sep 2006 15:50:25 +0200
> >
> >Dear All,
> >
> >I have this statement :
> >macrolist=%NRSTR(%mymacro1
> >(file=&file1,varlist=&varlist1,outfolder=&outfolder1));
> >I would like to test if macrolist is empty or not.
> >If I use
> >%if &macrolist. ne %then %do;
> >......
> >%end;
> >I get this error message :
> >ERROR: Required operator not found in expression: &macrolist. ne
> >Please do you know what I have to add ?
> >
> >Thank you very much in advance !
> >
> >yom
> >
> >
> >
>
>
>
From: Ian Whitlock on
Yom,

Some more points:

1) You will learn faster if you explain the real problem as
opposed to saying your solution has an error, since you
will then find out about better solutions than the one
you thought of and guide the helper in how to answer the
error you are facing.

2) Testing

%length(&macvar) > 0

is safer than

&macvar ne

because fewer thing need to be hidden by macro quoting.

3) It is a very bad habit to bury macro definitions inside macros.
Remember that the inner macro is compiled each and every time the
outer macro is executed and nothing is accomplished by nesting
macro definitions other than possibly preventing you from good
design habits.

4) It is often better leave the %-sign of a macro invocation
given in a parameter. In version 8.2+

%let mac = mymac(parm=abc) ;
%&mac

works quite well and saves a lot of quoting.

5) The macro compile time quoting functions %STR and %NRSTR leave
things hidden at macro execution time. Hence they should be
used when hiding a symbol at execution time.

6) The execution time quoting functions, %BQUOTE, %NRBQUOTE, and %SUPERQ
should not be used to hide a symbol; they only be used when the result of resolving
will reveal a problem symbol. It is worth forgetting about %BQUOTE and
%NRBQUOTE to standardize on %SUPERQ. Anytime the prior functions are
required the macro is too tricky to work anyway.

Ian Whitlock
================
Date: Tue, 5 Sep 2006 17:13:09 +0200
Reply-To: yom <yomsas(a)GMAIL.COM>
Sender: "SAS(r) Discussion"
From: yom <yomsas(a)GMAIL.COM>
Subject: Re: Check if macro parameter is empty
Comments: To: toby dunn <tobydunn(a)hotmail.com>
In-Reply-To: <BAY123-F14A01BF608027DB0C086CBDE300(a)phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Thank you very much ! Tonight I will go to bed being less stupid !
Best regards,
yom
<snip>
From: Yu Zhang on
Dear Members,

After I tried out the following code, I think the cause of the problem
should be parenthesis,( ). I am not sure what or how the %if statement is
evaluated. Apprently, when SAS macro facility saw a pair of parenthesis, it
will expect something. Could someone kindly provide more information about
%if statement evaluation? If I am totally looking at wrong target, please
let me know.

Thank you much!

Yu


/* I got same error meassge, even after I took off all the %,&'s */
%let macrolist=hello();
%macro MyMacro;
%if &macrolist ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;



On 9/5/06, Ian Whitlock <iw1junk(a)comcast.net> wrote:
>
> Yom,
>
> Some more points:
>
> 1) You will learn faster if you explain the real problem as
> opposed to saying your solution has an error, since you
> will then find out about better solutions than the one
> you thought of and guide the helper in how to answer the
> error you are facing.
>
> 2) Testing
>
> %length(&macvar) > 0
>
> is safer than
>
> &macvar ne
>
> because fewer thing need to be hidden by macro quoting.
>
> 3) It is a very bad habit to bury macro definitions inside macros.
> Remember that the inner macro is compiled each and every time the
> outer macro is executed and nothing is accomplished by nesting
> macro definitions other than possibly preventing you from good
> design habits.
>
> 4) It is often better leave the %-sign of a macro invocation
> given in a parameter. In version 8.2+
>
> %let mac = mymac(parm=abc) ;
> %&mac
>
> works quite well and saves a lot of quoting.
>
> 5) The macro compile time quoting functions %STR and %NRSTR leave
> things hidden at macro execution time. Hence they should be
> used when hiding a symbol at execution time.
>
> 6) The execution time quoting functions, %BQUOTE, %NRBQUOTE, and %SUPERQ
> should not be used to hide a symbol; they only be used when the
> result of resolving
> will reveal a problem symbol. It is worth forgetting about %BQUOTE
> and
> %NRBQUOTE to standardize on %SUPERQ. Anytime the prior functions are
> required the macro is too tricky to work anyway.
>
> Ian Whitlock
> ================
> Date: Tue, 5 Sep 2006 17:13:09 +0200
> Reply-To: yom <yomsas(a)GMAIL.COM>
> Sender: "SAS(r) Discussion"
> From: yom <yomsas(a)GMAIL.COM>
> Subject: Re: Check if macro parameter is empty
> Comments: To: toby dunn <tobydunn(a)hotmail.com>
> In-Reply-To: <BAY123-F14A01BF608027DB0C086CBDE300(a)phx.gbl>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Thank you very much ! Tonight I will go to bed being less stupid !
> Best regards,
> yom
> <snip>
>
From: Ian Whitlock on
Mark,

The real problem here is a bug or perhaps a mistake in the documentation.
Consider

66 %let macrolist=%nrstr(a(x));
67 %put %eval(&macrolist=) ;
ERROR: Required operator not found in expression: a(x)=

The documentation says about %STR and %NRSTR:

They also mask the following characters when they occur in pairs and
when they are not matched and are marked by a preceding % :
' " ( )

However,

68
69 %let macrolist=%nrstr(a%(x%));
70 %put %eval(&macrolist=) ;
0

shows that the problem with parentheses goes away when quoted. Hence
%NRSTR does not hide paired parentheses and the parentheses are involved
in the problem.

You can see that

%let macrolist=
%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf older1));

does in fact hide some symbols by looking at SASHELP.VMACRO. (There is no need
to assume that some mysterious hiding takes place with %PUT.) Moreover, you
can see that the paired parentheses are not hidden.

On the other hand, I cannot understand why the expression

%eval(a(x)=)

should require an operator? Since (X) causes no problem, it is apparently
the leading A plus the parentheses that cause the trouble.

You say that

%let
macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
older1));
%macro MyMacro;
%if %NRSTR(&macrolist.) ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;

cures the problem. This is not true! There is no error message becasue

&macrolist.

has 11 characters and thus is not empty. Consider

87 %let macrolist=;
88 %macro MyMacro;
89 %if %NRSTR(&macrolist.) ne %then
90 %do;
91 %put macrolist is >&macrolist<;
92 %end;
93 %mend;
94 %MyMacro;
macrolist is ><

Finally,

>%let
>macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
>older1));
>%macro MyMacro;
> %if %quote(&macrolist.) ne %then
> %do;
> %put macrolist is >&macrolist<;
> %end;
>%mend;
>%MyMacro;

does work because the parentheses are hidden by %QUOTE. This reinforces the
suspicion that there is a bug in %STR and %NRSTR rather than a mistake in
the documentation. The fact that %EVAL tries to evaluate A() may be a bug, but
I am less sure of this.

Ian Whitlock
=================
Date: Tue, 5 Sep 2006 07:35:25 -0700
Reply-To: "Terjeson, Mark" <Mterjeson(a)RUSSELL.COM>
Sender: "SAS(r) Discussion"
From: "Terjeson, Mark" <Mterjeson(a)RUSSELL.COM>
Subject: Re: Check if macro parameter is empty
Comments: To: yom <yomsas(a)GMAIL.COM>
Content-Type: text/plain; charset="us-ascii"
Hi yom,


* your original version ;
%let
macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
older1));
%macro MyMacro;
%if &macrolist. ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;


* *** A TIMING SUBTLETY ***;
* you can see by the two samples below that the %NRSTR gets used ;
* upon resolution. i.e. not during the %LET assignment, but in ;
* the %PUT when the &macrolist gets resolved! You cannot tell ;
* by the %LET and %PUT by themselves, but when we compare it to ;
* the following macro, and which error messages you get!!! ;
%let
macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
older1));
%put macrolist is >&macrolist<; * as seen here ;
* at this point it you can see that the %NRSTR is gobbled up, ;
* but you cannot tell if it is at assignment-or-resolution-time. ;



* if at assignment-time, text-substitution would yield ;
%macro MyMacro;
%if %mymacro1(file=&file1,varlist=&varlist1,outfolder=&outfolder1)
ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;
* error messaging not the same as your original message ;

* if at resolution-time, text-substitution would yield ;
%macro MyMacro;
%if
%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outfolder1))
ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;
* error messaging is the same as your original message, ;
* except for the obvious portrayal of the difference in ;
* the text being shown back to you. ;



* since all macro variables are string, merely informing ;
* the compiler that that is what you want to evaluate is ;
* going to eliminate any error messages. ;
* you can use several functions to effectively wrap the ;
* string as a whole and not have it parsed out... ;
%let
macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
older1));
%macro MyMacro;
%if %NRSTR(&macrolist.) ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;

-or-

%let
macrolist=%NRSTR(%mymacro1(file=&file1,varlist=&varlist1,outfolder=&outf
older1));
%macro MyMacro;
%if %quote(&macrolist.) ne %then
%do;
%put macrolist is >&macrolist<;
%end;
%mend;
%MyMacro;

Hope this is helpful,
Mark Terjeson


-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L] On Behalf Of yom
Sent: Tuesday, September 05, 2006 6:50 AM
To: SAS-L
Subject: Check if macro parameter is empty
Dear All,
I have this statement :
macrolist=%NRSTR(%mymacro1
(file=&file1,varlist=&varlist1,outfolder=&outfolder1));
I would like to test if macrolist is empty or not.
If I use
%if &macrolist. ne %then %do;
......
%end;
I get this error message :
ERROR: Required operator not found in expression: &macrolist. ne Please
do you know what I have to add ?
Thank you very much in advance !
yom