BookmarkSubscribeRSS Feed
jenwright
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?
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
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
[pre]
Name Bday
alan -3334
bob 9099
carl -3053
[/pre]

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

proc print data=mydata;
format bday monyy5.;
run;

proc print data=mydata;
format bday year4.;
run;
[/pre]

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:

[pre]
proc contents data=mydata;
title 'what are my variables';
run;
[/pre]

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)

cynthia

Results from code above (on the BDAY variable)
[pre]
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

[/pre]

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1187 views
  • 0 likes
  • 2 in conversation