03-17-2016 07:31 AM
I am trying to convert datetime formats into month-year format in SAS and use them to sum a column by month and year. I have tried using 100*YEAR(DATEPART(DATE_VALUE))+MONTH(DATEPART(DATE_VALUE)) and it does work. But when I try to plot them on a graph, the dates are considered as numerical values which results in some random numbers on the horizontal axis.
I have used the MMMYY formats, but those only format the dates into MONTH-YEAR format, they dont actually change the values of the date, and it wont let me group the columns by month and year, since their actual values are still unique.
03-17-2016 08:26 AM
It is always a good idea to post test data (in a datastep) of what you have, and what you want the output to look like. I have taken a guess at the below:
data have; thedt="01JAN2014:01:00:00"dt; val=6; output; thedt="01JAN2014:06:10:00"dt; val=18; output; thedt="04MAR2014:03:00:00"dt; val=6; output; thedt="15MAR2014:04:00:00"dt; val=7; output; thedt="12JAN2015:01:00:00"dt; val=5; output; thedt="14JAN2014:01:00:00"dt; val=10; output; run; proc sql; create table WANT as select YEAR, MONTH, sum(VAL) as RESULT from (select year(datepart(THEDT)) as YEAR,month(datepart(THEDT)) as MONTH,VAL from HAVE) group by YEAR,MONTH; quit;
03-17-2016 09:57 AM
What do you mean it considers the actual date?
Proc SQL doesn't recognize formats when using Group By, but proc means and proc freq will.