BookmarkSubscribeRSS Feed
markc
Obsidian | Level 7

Hello,

 

How can I easily produce a chart of the number of observations that occurred per week based on a date field on each observation over the previous 3 months from a parameter date?

 

Specifically, I am wondering if there is a proc which can do most of the work of this, where you give it a dataset with the dates and it then clusters the number of observations by week, going back a specified number of intervals (in this case 3 weeks) and then produces a table or chart.

 

Kind regards,

Mark

3 REPLIES 3
PGStats
Opal | Level 21

If date and parmdate are SAS dates, you can use

 

weeks = intck("WEEK", date, parmDate, "Continuous")

 

to get the number of weeks between date and parmDate.

PG
andreas_lds
Jade | Level 19

Please post example data, the expected result and a value the parameter date contains.

 

It seems that you need a where-statement to get the observations of the 3 month before param_data. Assuming that the parameter contains the string 9Sep2018 (value taken from EG prompt): where data_date >= intnx('month', "&promptDate."d, -3, 's')

 

To get the number of observations per week, applying a format like weekv5 and using a proc like summary or freq could yield the required result. But without any data shown, this is pure guesswork.

ballardw
Super User

@markc wrote:

Hello,

 

How can I easily produce a chart of the number of observations that occurred per week based on a date field on each observation over the previous 3 months from a parameter date?

 

Kind regards,

Mark


How does the "parameter date" get involved? Is that used to filter data or indicate the first day of a "week" and calculate weeks based on seven day intervals from the parameter of something else? By previous 3 months do you mean from the first day of the month 3 previous or go back to the same day of the month 3 previous?

And which day of the week starts your week?

How do you want "week" interpreted if your period crosses year boundaries?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1761 views
  • 4 likes
  • 4 in conversation