Hello,
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.
Then use the format in a put() function, the result is stored as a char: WYSIWYG.
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;
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.
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.