Let say I want to create a macro variable like:
%let year=2019;
%let ye = SUBSTR(%year,3,2) (I want to extract 19 from 2019).
But it does not work. Do we have any of creating such a macro variable like this?
Update: My code in fact is like
%let yearend = 2019
% let monthend = 04
And now I want to create a macro variable like "data1904" in order to use the dataset named "data1904" in my library. So what I want to create is something like
%let dataname= CAT(SUBSTR(%yearend,3,2),%monthend)
You use & to reference a macro variable, not %.
When you use a function in macro code you need to wrap it in %SYSFUNC()
so the compiler can differentiate between text and code.
%let ye = %sysfunc(substr(&year, 3, 2));
Or alternatively there is the %SUBSTR()
macro function which allows you to skip the %SYSFUNC().
%let ye = %substr(&year, 3, 2);