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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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