BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Amir
PROC Star

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.

 

Ksharp
Super User
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;
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
  • 2 replies
  • 829 views
  • 2 likes
  • 3 in conversation