I want to convert today() in charakter.
My idea was:
%Let Mydate="put(today() date9.)" ;
But it seems I have an error in my thinking.
You mix up several things :
- macro instructions/functions (beginning with %)
- base sas language, data step functions.
You can use a datastep function in a macro instruction with %sysfunc.
If you want to create a variable in a dataset with today's date :
data have;
myDate=put(today(), date9.);
put myDate=;
run;
If you want to create a macrovariable instead :
%let myDate=%sysfunc(putn(%sysfunc(today()),date9.));
%put &=myDate.;
Or
data _NULL_;
myDate=put(today(), date9.);
call symputx("myDate",myDate);
run;
You mix up several things :
- macro instructions/functions (beginning with %)
- base sas language, data step functions.
You can use a datastep function in a macro instruction with %sysfunc.
If you want to create a variable in a dataset with today's date :
data have;
myDate=put(today(), date9.);
put myDate=;
run;
If you want to create a macrovariable instead :
%let myDate=%sysfunc(putn(%sysfunc(today()),date9.));
%put &=myDate.;
Or
data _NULL_;
myDate=put(today(), date9.);
call symputx("myDate",myDate);
run;
data _null_;
date1=input(put(today(),yymmdd8.),yymmdd8.);
put date1;
format date1 date9.;
run;
Thanks the solutions:
%let myDate=%sysfunc(putn(%sysfunc(today()),date9.));
or
&sysdate9
work for me.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.