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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.