Hello
What is the way to convert values (char values) as Q4-2024,Q3-2024,Q2-2024,Q1-2024,Q1-2025 to sas date?
Data have;
input Quarter_Year $;
cards;
Q4-2024
Q3-2024
Q2-2024
Q1-2024
Q1-2025
;
Run;
Data have;
input Quarter_Year $;
cards;
Q4-2024
Q3-2024
Q2-2024
Q1-2024
Q1-2025
;
Run;
data want;
set have;
date=input(cats(scan(Quarter_Year,-1,'-'),scan(Quarter_Year,1,'-') ),yyq8.);
format date date9.;
run;
Hi,
You could try something like the following. It uses the YYQ function, which "returns a SAS date value that corresponds to the first day of the specified quarter."
data want;
set have;
format date2 date9.;
date1 = yyq(input(scan(quarter_year,2),8.),input(char(quarter_year,2),8.));
date2 = date1;
run;
Thanks & kind regards,
Amir.
Data have;
input Quarter_Year $;
cards;
Q4-2024
Q3-2024
Q2-2024
Q1-2024
Q1-2025
;
Run;
data want;
set have;
date=input(cats(scan(Quarter_Year,-1,'-'),scan(Quarter_Year,1,'-') ),yyq8.);
format date date9.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.