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

Hi guys,

 

I am trying to convert quarters to date, like 2007Q1 (I am having as this in my dataset) to 31/03/2007.

Can you please help me with the program?

 

Cheers

Amanjot

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below should work.

data test;
  format sas_date_value ddmmyy10.;
  quarter_string='2007Q1';
  sas_date_value=intnx('quarter',input(quarter_string,yyq6.),0,'e');
  output;
  stop;
run;
proc print data=test;
run;

Capture.JPG 

View solution in original post

9 REPLIES 9
Patrick
Opal | Level 21

@amanjot_42 wrote:

Hi guys,

 

I am trying to convert quarters to date, like 2007Q1 (I am having as this in my dataset) to 31/03/2007.

Can you please help me with the program?

 

Cheers

Amanjot


Is the variable holding 2007Q1 of type character or numeric?

amanjot_42
Fluorite | Level 6
Hi, thanks for replying,
Its character!
Patrick
Opal | Level 21

Below should work.

data test;
  format sas_date_value ddmmyy10.;
  quarter_string='2007Q1';
  sas_date_value=intnx('quarter',input(quarter_string,yyq6.),0,'e');
  output;
  stop;
run;
proc print data=test;
run;

Capture.JPG 

amanjot_42
Fluorite | Level 6

Thanks,

 

But I have noticed that I need this conversion for full one column named 'dataquater' with values like 2007Q1 2007Q2 and so on.

Is this code works for full column?

 

 

Kurt_Bremser
Super User

@amanjot_42 wrote:

Thanks,

 

But I have noticed that I need this conversion for full one column named 'dataquater' with values like 2007Q1 2007Q2 and so on.

Is this code works for full column?

 

 


Of course it will work. A data step iterates through all observations in the dataset used in the set statement.

@Patrick just had to make up usable data artificially because you did not provide an example dataset; otherwise his data step would have taken your dataset as input.

amanjot_42
Fluorite | Level 6

Here is the code:

 

data want;
set have;
format sas_date_value ddmmyy10.;
quarter_string='2007Q1';
sas_date_value=intnx('quarter',input(quarter_string,yyq6.),0,'e');
output;
stop;
run;

 

But this shows result for only one observation at the end. Even I tried this with column name: quarter_string=dataquarter

Same results showing for one observation only!

 

Kurt_Bremser
Super User

Remove the unnecessary statements, and use your variable from the dataset:

data want;
set have;
format sas_date_value ddmmyy10.;
sas_date_value=intnx('quarter',input(dataquater,yyq6.),0,'e');
run;

Read the documentation for the meaning of the output and stop statements.

amanjot_42
Fluorite | Level 6

thanks!

It worked well.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 1769 views
  • 0 likes
  • 3 in conversation