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 ?
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?
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).
@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.
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!
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.
Ready to level-up your skills? Choose your own adventure.