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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 752 views
  • 2 likes
  • 3 in conversation