BookmarkSubscribeRSS Feed
rkumar23
Calcite | Level 5

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.?

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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);

Tom
Super User Tom
Super User

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.

Ksharp
Super User

Check  %eval() and %sysevalf()

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
  • 3 replies
  • 3274 views
  • 0 likes
  • 4 in conversation