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;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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