Help using Base SAS procedures

simple date questions

Not applicable
Posts: 1

simple date questions

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?
Posts: 9,371

Re: simple date questions

Posted in reply to jenwright
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

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation