can't get todays data.Please help.can we not call global macro in data step?
data a;
infile cards;
input test$ date anydtdte.;
format date yymmddn8.;
cards;
a 20200713
b 20200713
c 20200707
d 20200708
e 20200709
uf 20200710
;
run;
%let today = %sysfunc(today(),yymmddn8.);
%put "&today.";
data test;
set a;
if date=&today;
run;
In most cases it is not a good idea to store formatted dates in macro-variables. This is one of those cases.
In a data-step a format has no influence on the value stored in the dataset, the format only influences what you see.
So please try:
data test;
set a;
if date = today();
run;
If you really need today's date in a macro-variable don't use the second parameter of %sysfunc:
%let today = %sysfunc(today());
In most cases it is not a good idea to store formatted dates in macro-variables. This is one of those cases.
In a data-step a format has no influence on the value stored in the dataset, the format only influences what you see.
So please try:
data test;
set a;
if date = today();
run;
If you really need today's date in a macro-variable don't use the second parameter of %sysfunc:
%let today = %sysfunc(today());
Hi,
Please use the date format while defining the macro:
%let today = %sysfunc(today(),yymmddn8.);
%put date=&today;
And then when you are creating the dataset A, you have to mention the codition with input statment, because now the macro value is character and you are filtering the data as date value which a different datatype.
SAS is not recognizing your macro variable &today as a date. It is recognizing it as the number 20200713. Remove the format in your %sysfunc(today()) step, and it will return the number of days since 1/1/1960, which is 22109. SAS will recognize that as your date.
data a;
infile cards;
input test$ date anydtdte.;
format date yymmddn8.;
cards;
a 20200713
b 20200713
c 20200707
d 20200708
e 20200709
uf 20200710
;
run;
%let today = %sysfunc(today());
%put &=today;
data test;
set a;
if date=&today;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.