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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 846 views
  • 0 likes
  • 2 in conversation