Hello Experts,
I would like to display my data as 2025100513 (yyyymmddtt). My code seems do not work and I can not find the right format here : SAS Help Center: Working with Dates and Times By Using the ISO 8601 Basic and Extended Notations.
I have this error message : ERROR: Format name B8601DT10.0 not found or the width and/or decimal specified for the format used are out of range. Thank you for your help.
This my code :
%let Ma_Date=%sysfunc(compress(%sysfunc(datetime(),B8601DT10.0),T));
@SASdevAnneMarie wrote:
Hello Experts,
I would like to display my data as 2025100513 (yyyymmddtt). My code seems do not work and I can not find the right format here : SAS Help Center: Working with Dates and Times By Using the ISO 8601 Basic and Extended Notations.
I have this error message : ERROR: Format name B8601DT10.0 not found or the width and/or decimal specified for the format used are out of range. Thank you for your help.
This my code :
%let Ma_Date=%sysfunc(compress(%sysfunc(datetime(),B8601DT10.0),T));
It is telling you that the format you have chosen is not wide enough. B8501DT must have a width of between 15 and 26. So this works:
%let Ma_Date=%sysfunc(putn(%sysfunc(datetime()),B8601DT15.0));
%put &=ma_date;
If you don't want the minutes and seconds in the output, you can use the %substr function to chop off the last 4 unwanted digits.
@SASdevAnneMarie wrote:
Hello Experts,
I would like to display my data as 2025100513 (yyyymmddtt). My code seems do not work and I can not find the right format here : SAS Help Center: Working with Dates and Times By Using the ISO 8601 Basic and Extended Notations.
I have this error message : ERROR: Format name B8601DT10.0 not found or the width and/or decimal specified for the format used are out of range. Thank you for your help.
This my code :
%let Ma_Date=%sysfunc(compress(%sysfunc(datetime(),B8601DT10.0),T));
It is telling you that the format you have chosen is not wide enough. B8501DT must have a width of between 15 and 26. So this works:
%let Ma_Date=%sysfunc(putn(%sysfunc(datetime()),B8601DT15.0));
%put &=ma_date;
If you don't want the minutes and seconds in the output, you can use the %substr function to chop off the last 4 unwanted digits.
Maxim 1: Read the Documentation.
specifies the width of the output field.
Default | 19 |
---|---|
Range | 15–26 |
So you can't use this format with a length of 10.
Roll your own custom format with PROC FORMAT:
proc format;
picture ymdh
low-high = '%Y%0m%0d%0H' (datatype=datetime)
;
run;
data _null_;
x = datetime();
put x= ymdh10.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.