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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 944 views
  • 0 likes
  • 3 in conversation