DATA Step, Macro, Functions and more

Is the macro correct?

Reply
Contributor
Posts: 49

Is the macro correct?

I wrote the macro indd and I'm wondering why the macro can't be resolved when I call the macro by: %put  i'm running %indd(no).

Is there something wrong with the macro? Thanks in advance.

%macro indd(in);

%if %upcase(&in)=YES %THEN %do;

%end;

%else %do;

noint

%end;

%mend;

%put  i'm running %indd(no);

Contributor
Posts: 49

Re: Is the macro correct?

Posted in reply to MikeTurner

I tried the codes on my colleague's computer and it worked fine. But not on my computer. It's so weird.

Super User
Posts: 10,046

Re: Is the macro correct?

Posted in reply to MikeTurner

Due to this special single quote :  i'm running

%macro indd(in);

%if %upcase(&in)=YES %THEN %do;

 yes

%end;

%else %do;

noint

%end;

%mend;

option mprint symbolgen mlogic; 

%put  %str(i%'m running) %indd(no) ;

Ksharp

Contributor
Posts: 49

Re: Is the macro correct?

Thank you, Ksharp.

I tried your codes and still didn't work. I suspected something wrong with my computer's setting.

I tried your codes and my codes on my colleague's computer and all worked fine.

Thanks. 

Super User
Posts: 10,046

Re: Is the macro correct?

Posted in reply to MikeTurner

It is so weird .Did you open a new sas session ? What is your log ?

Contributor
Posts: 49

Re: Is the macro correct?

I opened a new sas session. It seemed that the codes sometimes worked fine and sometimes not.  Please have a look at the log. Thank all.

16   %macro indd(in);

17   %if %upcase(&in)=YES %THEN %do;

18

19   %end;

20   %else %do;

21   noint

22   %end;

23   %mend;

15   %put  i'm running %indd(no);

            ---------------------

            49

NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS

             release.  Inserting white space between a quoted string and the succeeding

             identifier is recommended.

24   option mprint symbolgen mlogic;

25   %put  i'm running %indd(no);

MLOGIC(INDD):  Beginning execution.

MLOGIC(INDD):  Parameter IN has value no

SYMBOLGEN:  Macro variable IN resolves to no

MLOGIC(INDD):  %IF condition %upcase(&in)=YES is FALSE

MLOGIC(INDD):  Ending execution.

i'm running %indd(no);%macro indd(in);%if %upcase(&in)=YES %THEN %do;%end;%else

%do;noint%end;%mend;option mprint symbolgen mlogic;%put  i'm running noint

26   %put  i'm running %indd(no);

Super Contributor
Posts: 474

Re: Is the macro correct?

Posted in reply to MikeTurner

OK, I got it.

Code tested was actually the one Ksharp posted, which runs fine.

It's the ' char inside the %put

It's totally messing the compiler, that's why you get erratic runs.

As Ksharp suggested, enclose it inside a masking macro functions so the compiler can get the code right.

%str(%')

More on masking here:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001061345.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

Super Contributor
Posts: 474

Re: Is the macro correct?

Posted in reply to MikeTurner

Runs fine. Nothing wrong about your code.

Please share the log and context of your session.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

Ask a Question
Discussion stats
  • 7 replies
  • 246 views
  • 0 likes
  • 3 in conversation