- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I've one field called 'Calendar_Month' and it is in date9. Format and I want to convert that field to character and the value should appear like YYYY-MM.
Ex:
AS IS:
Calendar_Month (numeric with date9. format)
07Jan2020
TO BE:
Calendar_Month (Need in character)
2020-01
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the YYMMd format:
str=put(date,yymmd7.);
The "d" in the format name modifies the output to use a dash separator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the YYMMd format:
str=put(date,yymmd7.);
The "d" in the format name modifies the output to use a dash separator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
like this?
data test;
dt='07JAN2020'd;
dtnew=put(dt, yymmd.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello @David_Billa,
Use the YYMMD. format:
data want(drop=_cm);
set have(rename=(Calendar_Month=_cm));
Calendar_Month=put(_cm,yymmd.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You want the new character variable to have the same name as the original numeric variable. The type of an existing variable cannot be changed in place, hence we need two separate variables and different variables must have different names. So, at some point we need to change the old name to a new name (that's what I did with the RENAME= dataset option) or vice versa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@David_Billa wrote:
Can't we do it without rename statement?
In fact, @FreelanceReinh does not use a statement, but a dataset option. These are two different things.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I merged your two, basically identical, questions.