dear all,
I would like to create a quarter variable based on a date variable.
The FORMAT of the date is YYMMDDD10. (e.g.,1990-09-29). I use the code like
DATA Step1.Appln_newQuarter;
SET Step1.appln_new;
IF MONTH(earliest_filing_date)=1 or 2 or 3 THEN quarter=1;
ELSE IF MONTH(earliest_filing_date)=4 or 5 or 6 THEN quarter=2;
ELSE IF MONTH(earliest_filing_date)=7 or 8 or 9 THEN quarter=3;
ELSE IF MONTH(earliest_filing_date)=10 or 11 or 12 THEN quarter=4;
RUN;but the result is '1'. could you please give me some suggestions?
thanks in advance.
DATA Step1.Appln_newQuarter;
SET Step1.appln_new;
quarter=qtr(earliest_filing_date);
RUN;
Use the qtr function -- is all you need i think
DATA Step1.Appln_newQuarter;
SET Step1.appln_new;
quarter=qtr(earliest_filing_date);
RUN;
Use the qtr function -- is all you need i think
@France wrote:
dear all,
I would like to create a quarter variable based on a date variable.
The FORMAT of the date is YYMMDDD10. (e.g.,1990-09-29). I use the code like
DATA Step1.Appln_newQuarter; SET Step1.appln_new; IF MONTH(earliest_filing_date)=1 or 2 or 3 THEN quarter=1; ELSE IF MONTH(earliest_filing_date)=4 or 5 or 6 THEN quarter=2; ELSE IF MONTH(earliest_filing_date)=7 or 8 or 9 THEN quarter=3; ELSE IF MONTH(earliest_filing_date)=10 or 11 or 12 THEN quarter=4; RUN;but the result is '1'. could you please give me some suggestions?
thanks in advance.
For a very large number of purposes you may not even need to create an additional variable at all. SAS provides several formats for date values that will display quarters: QTRw. by default displays 1 to 4, QTRRw. which displays quarter as Roman numerals: I II III and IV, YYQw which will show year and quarter information together depending on width YYQ. default shows YYYYQn such as 2018Q1 or YYQxw. where you choose a charcter for x that controls the separator between the year and quarter numbe allowing such things as 2012/3 or 2017-2.
Analysis procedures will honor the formatted value for grouping purposes.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.