- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I’m pretty new to SAS EG 8.3 and I’m trying to convert character date (ex. 20210111) to show as Year/Month (ex. 2021/01) but cant get it right.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this can be done in the query builder. You can create a computed column with the advanced expression editor, but you would use the INPUT function and the YYMMDD8. informat to convert the character string to a SAS date, and then apply the YYMMS7. format to display the SAS date correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
sorry for the multiple posts. tried to include a screen shot but it said it doesn't support file type and it wont let me delete the post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to create a new variable in a data step such as:
data want; set have; newdate = input(characterdate,yymmdd10.); format newdate yymms7. ; run;
Once you have a date value there are dozens of SAS supplied formats plus you can create your own format with Proc Format if you can't find one the matches your need.
Be aware the date value still has a day of the month component if you try to do any comparisons. The groups created by the format will work for most analysis, reporting and graphing procedures without modifying the individual values of the variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can it be done in Computed Columns in Query Builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this can be done in the query builder. You can create a computed column with the advanced expression editor, but you would use the INPUT function and the YYMMDD8. informat to convert the character string to a SAS date, and then apply the YYMMS7. format to display the SAS date correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content