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.;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2418 views
  • 1 like
  • 5 in conversation