Help using Base SAS procedures

simple date questions

Reply
N/A
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?
SAS Super FREQ
Posts: 8,742

Re: simple date questions

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]
Ask a Question
Discussion stats
  • 1 reply
  • 105 views
  • 0 likes
  • 2 in conversation