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!
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!
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!
It worked, I appreciate it!
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.