BookmarkSubscribeRSS Feed
ubshams
Quartz | Level 8

I was able to import data from Excel to SAS and it's now in this format:

 

Quarter   Variable1 Variabl2

201201      1               2

201202     1                2

201203     4                1

201204     5                1

....

....

201804      5                 8

 

They are all in number format (even the Quarter column values). How do I convert the quarter column's values to a Quarterly date

format? 

 

The final goal is to get the seasonal factors but need to set the dates correctly first.

Thanks in advance!

  

 

3 REPLIES 3
Reeza
Super User
So 201201 and 201202 are 2012Q01 and 2012Q2?
ubshams
Quartz | Level 8

Yes.

Reeza
Super User

Here's one method to convert it to a SAS date.

 

data have;
quarter = 201201;output;
quarter = 201202;output;
quarter = 201203;output;
quarter = 201204;output;
run;

data want;
set have;
qtr_char = catx('Q', substrn(quarter, 1, 4), substrn(quarter, 6, 1));
date = input(qtr_char, yyq6.);
format date yyqd6.;
run;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 754 views
  • 0 likes
  • 2 in conversation