BookmarkSubscribeRSS Feed
Calcite | Level 5
I have a SAS data set that has information by dates (mmddyy). I'd like to sum it up by month and year and then use it in a forecast. I can get it sum by a month and year but the forecast procedure doesn't recognize it as an id variable because it's not a "number/date". How do you turn dates into monthyear?
If your variable is
1) numeric
2) the number is the number of days since Jan 1, 1960

then try a format statement in your procedure:

format mydate monyy5.;

For example, if I have a date variable called BDAY, a numeric variable that represents birthdate, then this data
Name Bday
alan -3334
bob 9099
carl -3053

could be printed/displayed with:
proc freq data=mydata;
tables bday;
format bday mmddyy2.;

proc print data=mydata;
format bday monyy5.;

proc print data=mydata;
format bday year4.;

On the other hand, if your variable is a character string that represents a date, then you will need to create a numeric variable from the character variable -- probably in a data step program. Or, you could take an alternate approach and create a separate numeric variable for MONTH and a separate numeric variable YEAR. I hate to say that it depends, but it really does depend....on your forecasting procedure, on whether your date variable is numeric or character.

To find out the "type" of your variables -- either character or numeric, run PROC CONTENTS on your data set:

proc contents data=mydata;
title 'what are my variables';

Your best bet for help would be to call Tech Support because they can help you with the forecasting procedure question and the how to deal with your date variable question.

(Alan was born on 11/15/1950; Bob on 11/29/1984; and Carl on 08/23/1951)


Results from code above (on the BDAY variable)
The FREQ Procedure

Cumulative Cumulative
bday Frequency Percent Frequency Percent
11 2 66.67 2 66.67
08 1 33.33 3 100.00

Obs name bday

1 alan NOV50
2 bob NOV84
3 carl AUG51

Obs name bday

1 alan 1950
2 bob 1984
3 carl 1951


Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2 in conversation