0

In SAS DI studio I'm attempting to create a macro, and assign a value to it with a user written code transformation. How do I print the value of this macro to test if my code does what I want it to do.

I need a macro that takes a value based on the date when the project is run looking something like:

%let runYear = if month < 6 then year(today) - 1 else year(today)

Normally I would start with something simple like:

%let test = month(today())

And just look what that gives me and work it out, but I don't know how to display the value of 'test' in above example.

I am new to SAS DI studio and I realize this is a simple question but I couldn't find the answer. All I want to know is how to print a value from user written code / how do debug user written code.

  • Note that in SAS a macro is a function. What you are talking about is a what most users call a macro variable. In the documentation will see them referred to as symbols. – Tom Jul 15 '21 at 14:12

1 Answers1

0

To reference the value of a macro variable you use & before the name of the macro variable. So if the macro variable is named test then use &test for the value stored in test.

To display the value of a macro variable you could use the %put macro statement.

%put &test ;

The %put statement allows a special syntax that will display the name of the macro variable before the value.

%put &=test ;

Note that in your case the vlaue stored in your macro variable is just the text you displayed. So test has the string month(today()). That will work well if you expand the macro variable's value in the middle of a SAS statement as SAS will evaluate that string as a call to the month() and today() functions. But if you expected the macro variable to contain the result of those functions you would need to wrap each function call inside a call to the macro function %sysfunc(). Example:

151   %let test = month(today());
152   %put &=test;
TEST=month(today())
153
154   %let test = %sysfunc(month(%sysfunc(today())));
155   %put &=test;
TEST=7
Tom
  • 47,574
  • 2
  • 16
  • 29