SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
ywon111
Quartz | Level 8
Have a dataset with a quarter variable like below:

Quarter
202009
202003
202003
202006

Is there a way to convert this to a date? Ideally something like ddmmmyy

Thanks
8 REPLIES 8
PaigeMiller
Diamond | Level 26

Are these numeric values? Are these formatted as yymmn6.? Are they character values?

 

Depending on your answers above, the method to convert to dates changes.

--
Paige Miller
ywon111
Quartz | Level 8
They are not formatted. Importing from an excel and all it displays in
excel is 202009 (example). Thanks ##- Please type your reply above this
line. No attachments. -##
PaigeMiller
Diamond | Level 26

But I don't care how it displays in Excel. Is that how it displays in SAS? Is it numeric or character in SAS?

--
Paige Miller
ywon111
Quartz | Level 8
It's displayed as numeric in SAS.
Thanks
novinosrin
Tourmaline | Level 20

Hi @ywon111  , @PaigeMiller  is asking for the metadata/descriptor info or in other words properties of your sas dataset that was created by importing the contents of the excel file. 

 

To view the descriptor portion, you would need to run 

 

proc contents data=your_sasdataset;

run

 

The output of proc contents would contain whether your quarter variable is numeric or char and other info. Please provide that info and then based upon which the SAS community would recommend your much needed solution. Thank you!

ballardw
Super User

@ywon111 wrote:
Have a dataset with a quarter variable like below:

Quarter
202009
202003
202003
202006

Is there a way to convert this to a date? Ideally something like ddmmmyy

Thanks

Yes there is a way. Assuming the value you show is actually YYYYMM (not quarter but month). However the approach varies depending on 1) whether the value after you brought it into SAS is character or numeric   and 2) which particular date, which must include a day of the month, you want. The simplest SAS tools would assume that you want to create the first date of the calendar quarter such as 01/09/2020. If you expect something else from 202009 then you need to specify it.

ywon111
Quartz | Level 8

It's formatted as numeric in SAS.

 

From proc contents: Format: BEST12.

Kurt_Bremser
Super User

Since the variable shows months, not quarters, you can convert it with this:

quarter = input(put(quarter,6.),yymmn6.);
format quarter yymmdd10.;

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
  • 8 replies
  • 2050 views
  • 1 like
  • 5 in conversation