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.
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.
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.