Desktop productivity for business analysts and programmers

Char Date to SAS Date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Char Date to SAS Date

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!


Accepted Solutions
Solution
a month ago
Super User
Posts: 24,010

Re: Char Date to SAS Date

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


All Replies
Solution
a month ago
Super User
Posts: 24,010

Re: Char Date to SAS Date

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!


 

Occasional Contributor
Posts: 7

Re: Char Date to SAS Date

It worked, I appreciate it!

Super User
Posts: 13,941

Re: Char Date to SAS Date

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.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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