BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

 

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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());
rabindrakumar1
Obsidian | Level 7

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.

ketpt42
Quartz | Level 8

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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 793 views
  • 1 like
  • 5 in conversation