SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WorkUser
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
jebjur
SAS Employee

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.

 

jebjur_0-1621621640514.png

 

View solution in original post

6 REPLIES 6
WorkUser
Obsidian | Level 7
 
WorkUser
Obsidian | Level 7

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.  

ballardw
Super User

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.

WorkUser
Obsidian | Level 7

Untitled.png

Can it be done in Computed Columns in Query Builder? 

jebjur
SAS Employee

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.

 

jebjur_0-1621621640514.png

 

WorkUser
Obsidian | Level 7
Thank you so much!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 35201 views
  • 0 likes
  • 3 in conversation