Solved
New Contributor
Posts: 3

# Counting Observations by Month instead of Day/ Plotting

Hello everyone!

I'm just started learning SAS this year; working on a project now.

I have a dataset with 2 columns that looks like:

func_date   obs (number of observations)

19961023    2

19961102    3

19961103    2

...               ...

My final goal is to plot this dataset with months on the x-axis and number of observations on the y-axis. But since the dataset is too large, I would like to measure the number of observations for each month in each year (instead of by each date).

How would I be able to convert func_date from a character variable to a date variable and be able to count the number of observations by month. It'll be great to be able to convert data set to a time series dataset. Any help/suggestions on manipulating data / plotting time series data will be greatly appreciated. Thank you!!

Accepted Solutions
Solution
‎07-21-2012 10:23 AM
Frequent Contributor
Posts: 93

## Re: Counting Observations by Month instead of Day/ Plotting

The best way to do it is to define a temp variable as 1 and then use PROC TIMESERIES

data olddata;

set olddata;

temp=1;

run;

proc timeseries data=olddata out=newdata;

by func;

id date interval=month

accumulate=total

var temp;

run;

All Replies
Occasional Contributor
Posts: 15

## Re: Counting Observations by Month instead of Day/ Plotting

You can convert the char dates to SAS dates with:

DATE=INPUT(FUNC_DATE,YYMMDD8.);

you can then format date as               DATE9.

MONYY5.

and summarize using PROC SUMMARY

Occasional Contributor
Posts: 15

## Re: Counting Observations by Month instead of Day/ Plotting

Maybe that was a bit brief

You could do something like this

.

.

.

DATE=INPUT(FUNC_DATE,YYMMDD8.);

MONTH=MDY(MONTH(DATE),1,YEAR(DATE));

YEAR=YEAR(DATE);

FORMAT DATE DATE8. MONTH MONYY5.;

then use PROC SUMMARY to sum the OBS variable by year, month, etc...

New Contributor
Posts: 3

## Re: Counting Observations by Month instead of Day/ Plotting

I will try it!

Thanks so much!!

Solution
‎07-21-2012 10:23 AM
Frequent Contributor
Posts: 93

## Re: Counting Observations by Month instead of Day/ Plotting

The best way to do it is to define a temp variable as 1 and then use PROC TIMESERIES

data olddata;

set olddata;

temp=1;

run;

proc timeseries data=olddata out=newdata;

by func;

id date interval=month

accumulate=total

var temp;

run;

New Contributor
Posts: 3

## Re: Counting Observations by Month instead of Day/ Plotting

It worked perfectly on my data. Thanks so much!

🔒 This topic is solved and locked.