I wanna get back one character by calling this macro but there is an error:
%macro getcategory(date=);
%global category;
%if %year(date) < 2002 %then %do;
%let category = A;
%mend;
%getcategory(date=1999);
I tried with symput but not working.
>Solution :
It looks like you are trying to use the %year()
function to determine the year of the date
parameter that is passed to the getcategory
macro. However, the %year()
function is not part of the SAS language.
To get the year from a SAS date value, you can use the year()
function, which is part of the SAS date and time functions. Here is an example of how you might use it:
%macro getcategory(date=);
%global category;
%let year = %sysfunc(year(date));
%if &year < 2002 %then %do;
%let category = A;
%end;
%mend;
%getcategory(date=1999);
In this example, the %sysfunc()
function is used to call the year()
function within the macro. This is necessary because the year()
function is a SAS function, not a macro language function.
Note that the year()
function returns the year as a four-digit number, so you will need to compare it to the value 2002
rather than the value 2
.
I hope this helps! Let me know if you have any other questions.