BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aakash93
Calcite | Level 5

Hi I'm quite new to SAS. With that said, I'm trying to convert a character date in the format of "Q12018" to SAS date. Preferably in the same format or similar format. Any help would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

SAS dates have a month day component attached. What would you want 2018 Q1 mapped to?

You can still display it in a similar format. 

 

data demo;
*numeric date;
date='01Jan2018'd;
*character date;
date_char = 'Q12018';

*conversion;
date_num = mdy(input(substr(date_char, 2, 1), 8.)*3, 
            1, 
            input(substr(date_char, 3), 8.)
            );

*apply formats for display;
format date date_num yyq6.;
run;

proc print data=demo;run;

@aakash93 wrote:

Hi I'm quite new to SAS. With that said, I'm trying to convert a character date in the format of "Q12018" to SAS date. Preferably in the same format or similar format. Any help would be appreciated!


 

View solution in original post

3 REPLIES 3
Reeza
Super User

SAS dates have a month day component attached. What would you want 2018 Q1 mapped to?

You can still display it in a similar format. 

 

data demo;
*numeric date;
date='01Jan2018'd;
*character date;
date_char = 'Q12018';

*conversion;
date_num = mdy(input(substr(date_char, 2, 1), 8.)*3, 
            1, 
            input(substr(date_char, 3), 8.)
            );

*apply formats for display;
format date date_num yyq6.;
run;

proc print data=demo;run;

@aakash93 wrote:

Hi I'm quite new to SAS. With that said, I'm trying to convert a character date in the format of "Q12018" to SAS date. Preferably in the same format or similar format. Any help would be appreciated!


 

aakash93
Calcite | Level 5

It worked, I appreciate it!

ballardw
Super User

One approach:

data example;
   char='Q12018';
   datenum= input(strip(catt(substr(char,3),substr(char,1,2))),yyq7.);
   put datenum=date9. datenum=yyq.;
run;

The yyq informat assigns the first day of the calendar quarter as the actual date value.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1573 views
  • 0 likes
  • 3 in conversation