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
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;
@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?
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;
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?
@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.
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!
thanks!
It worked well.
Please mark @Patrick's post as the solution, I only adapted it to your data.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.