I'm new to programming in SAS and I'm trying to create my own date format, which would be the name of the month, the year (4 digits) and the day (ALWAYS two digits), the problem is that from 1 to 9 it takes them as 1 single digit, and it would need to be 2 (with the 0 included). in the following way
I have it like this February20221 and I want it like this February202201
What I have done is this:
%let m=%sysfunc(putn(%sysfunc(today()), monname.));
%let y=%sysfunc(putn(%sysfunc(today()), year));
%let d=%sysfunc(putn(%sysfunc(today()), day));
%let date= %sysfunc(cat(&m,&y,&d));
How could I add this? I have tried with the cat function, with put, input... everything, but it always eliminates the 0 on the right.
Thank you very much in advance
CodePudding user response:
Proc Format is the right tool to create a custom date format.
Here is what's going on in Proc Format:
- The Picture Statement creates a Picture Format. A Picture Format tells SAS how to display a number (a SAS date is an integer).
dtfmtis the name of the format and the Default Option sets the length.- The Other Keyword specifies that the format should be applied to all values it encounters.
- %B%Y is a series of Directives. Directives specify how a date value should be presented. You can see a full list of directives here.
See if this works for you
proc format;
picture dtfmt (default=30)
other = '%B%Y
' (datatype=date)
;
run;
%let date= %sysfunc(date(), dtfmt.);
%put &date.;
This prints:
February202201
Note: The result may be different based on your Locale System Option.
