BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gracetones
Fluorite | Level 6

I have a date in char which looks like this Q1 2018. Not sure how to convert it to any date formats.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
And are you sure you want March 1 as the output? That's an unconventional Q1 start. If it's character here's one way:

data demo;
*create variable to test;
x='Q12018';

*reorder to 2018Q1;
y=catt(substr(x, 3, 4), 'Q', substr(x, 2, 1));

*import as a date;
sas_date = input(y, yyq6.);

*increment to custom interval;
quarter_start = intnx('month', sas_date, 2, 'b');

*apply format to view;
format sas_date quarter_start date9.;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User

What is the variable type and format?

 


@gracetones wrote:

I have a date in char which looks like this Q1 2018. Not sure how to convert it to any date formats.


 

Reeza
Super User
And are you sure you want March 1 as the output? That's an unconventional Q1 start. If it's character here's one way:

data demo;
*create variable to test;
x='Q12018';

*reorder to 2018Q1;
y=catt(substr(x, 3, 4), 'Q', substr(x, 2, 1));

*import as a date;
sas_date = input(y, yyq6.);

*increment to custom interval;
quarter_start = intnx('month', sas_date, 2, 'b');

*apply format to view;
format sas_date quarter_start date9.;
run;

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

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
  • 2 replies
  • 1448 views
  • 1 like
  • 2 in conversation