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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1525 views
  • 1 like
  • 5 in conversation