- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do I display date in the YYYYMMDD format? Like 1960/02/21.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to continue to use the same variable name, you need to output the result as character. For example:
datevar = put ( input(datevar, mmddyy10.), yymmdds10. );
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The yymmdd format is what you are looking for.
data test;
datevar = date();
format datevar yymmdd10.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I can't test it right now, but you should be able to control the separator as well:
format datevar yymmdds10.;
format datevar yymmddd10.;
s = slash
d = dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Astounding wrote:
I can't test it right now, but you should be able to control the separator as well:
format datevar yymmdds10.;
format datevar yymmddd10.;
s = slash
d = dash
The default separator for the YYMMDD format is the dash or hyphen.
Possible separators for the extended version of the format (as @Astounding posted) are
n no separator
b blank
d dash
s slash
p period
c colon
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What about if my date is a character variable and not numeric? For example: I have 11/5/1969 read in as character and I need to change it to the YYYYMMDD format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Depending on the format, do
datvar = input(stringvar,ddmmyy10.);
or
datvar = input(stringvar,mmddyy10.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to continue to use the same variable name, you need to output the result as character. For example:
datevar = put ( input(datevar, mmddyy10.), yymmdds10. );