The SAS Output Delivery System and reporting techniques

passing numeric value in the MACRO

Reply
Frequent Contributor
Posts: 78

passing numeric value in the MACRO

Could somebody help me with passing numeric value to the Macro variable...

example :

%MACRO1(TPM=1000,X1=TEST);

%MACRO MACRO1(TPM,X1);

%PUT "This is the value of &TPM";

%MEND MACRO1;

However as i understand Macro take only Text how do i make sure it has numeric value inside of the macro while execution.?

Super User
Super User
Posts: 7,942

Re: passing numeric value in the MACRO

How are you using the macro variable?  It depends on the situation, but you could do a check in your macro per:

%MACRO MACRO1(TPM,X1);

  %if %sysfunc(anyalpha("&TPM."))>0 %then %put "Non numeric found";

  %else %PUT "This is the value of &TPM";

%MEND MACRO1;

%MACRO1(TPM=a10a00,X1=TEST);

Super User
Super User
Posts: 7,039

Re: passing numeric value in the MACRO

Just use the macro variable reference at any place that you would normally type the number into your code.  Remember that macro is mainly just to generate code that will then be compiled and run the same as if it had been typed into the original program.

%macro loopy(start,stop);

DO i=&start TO &stop ;

   PUT i=;

END;

%mend loopy;

data _null_;

  %loopy(start=5, stop=10);

run;

It is only of concern if you are trying to pass a floating point number and compare its value to the value of a dataset variable. Then you might need to adjust for rounding.

Super User
Posts: 10,018

Re: passing numeric value in the MACRO

Check  %eval() and %sysevalf()

Ask a Question
Discussion stats
  • 3 replies
  • 877 views
  • 0 likes
  • 4 in conversation