BookmarkSubscribeRSS Feed
Gieorgie
Quartz | Level 8

I have a function that should define the current date in the table for the day

%let gv_date_dly=%sysevalf(%bquote('&date_dly.'d));
%let y=%sysfunc(year(&gv_date_dly.),z4.);
%let m=%sysfunc(month(&gv_date_dly.),z2.); 
%let d=%sysfunc(day(&gv_date_dly.),z2.);
%let gv_tbl_date=%eval(%str(&y&m&d));

However, the table shows me such a date.: How to change to for example to 2021-08-31 ?

 

Gieorgie_0-1633511066238.png

 

6 REPLIES 6
Kurt_Bremser
Super User

What is contained in &date_dly?

Run

%put &=date_dly.;

and show us the log.

Today's date is delivered by the TODAY() function, so use that:

%let gv_date_dly=%sysfunc(today());
%let y=%sysfunc(year(&gv_date_dly.),z4.);
%let m=%sysfunc(month(&gv_date_dly.),z2.); 
%let d=%sysfunc(day(&gv_date_dly.),z2.);
%let gv_tbl_date=%eval(%str(&y&m&d));

%put &=y. &=m. &=d. &=gv_tbl_date.;

Log:

 69         %let gv_date_dly=%sysfunc(today());
 70         %let y=%sysfunc(year(&gv_date_dly.),z4.);
 71         %let m=%sysfunc(month(&gv_date_dly.),z2.);
 72         %let d=%sysfunc(day(&gv_date_dly.),z2.);
 73         %let gv_tbl_date=%eval(%str(&y&m&d));
 74         
 75         %put &=y. &=m. &=d. &=gv_tbl_date.;
 Y=2021 M=10 D=06 GV_TBL_DATE=20211006

How do you use the macro variables in the code that creates the dataset?

Gieorgie
Quartz | Level 8
I think I wrote it wrong, the point is that when I start % put & = date_dly .; I can choose the dates e.g. I want the last reporting period at the end of the month and I choose 2021-08-31
Gieorgie
Quartz | Level 8
Its resolved i has removed datepart front of(zab_DATA_SPR) Thanks for help !
Kurt_Bremser
Super User

DATEPART is used to retrieve a date from a datetime value. Dates are counts of days, datetimes are counts of seconds, both starting at 1960-01-01 and 1960-01-01:00:00:00, respectively.

So DATEPART is actually FLOOR(datetime / 86400), which means that using it on a date results in a fairly small number that translates to 1960-01-01 (day zero) or 1959-31-12 (for dates before the zero point).

Ksharp
Super User
%let gv_date_dly=%sysevalf('01jan2020'd);
%let y=%sysfunc(year(&gv_date_dly.),z4.);
%let m=%sysfunc(month(&gv_date_dly.),z2.);
%let d=%sysfunc(day(&gv_date_dly.),z2.);

%put _user_;
ballardw
Super User

@Gieorgie wrote:

I have a function that should define the current date in the table for the day

%let gv_date_dly=%sysevalf(%bquote('&date_dly.'d));
%let y=%sysfunc(year(&gv_date_dly.),z4.);
%let m=%sysfunc(month(&gv_date_dly.),z2.); 
%let d=%sysfunc(day(&gv_date_dly.),z2.);
%let gv_tbl_date=%eval(%str(&y&m&d));

However, the table shows me such a date.: How to change to for example to 2021-08-31 ?

And how do you expect to use that GV_TABL_Date value? If you want to use it to select or compare with date values you want an actual date value, not a string of numbers that a human might interpret as date.

The actual numeric date value for 31 August 2021 is 22523. That would be the basis for comparison or manipulating using any of the date related functions. You can't even make 2021-08-31 into a date value easily.You would have to parse the parts and stick them into the MDY function.

If your dates are numeric and formatted to look like 2021-08-31 you still want the numeric underlying value, not the formatted text for most things. About the only time to format a macro variable with date information is for use in Title, Footnote, text for people to read, or file/dataset names.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1337 views
  • 1 like
  • 4 in conversation