Getting the average for multiple samples for variables in SAS - sas

I have a time-series data set with 5 minute resolution for 4 years in SAS. In this data set,a particular several variables (e.g., SRAD) is measured for each 5 minutes at 9 different stations (e.g., ST1,..., ST9). It means for each 5 minute interval (for example, Feb. 1, 2015 1:00:00 PM) there are 9 samples for this variable. Here is are some of my variables:
Interval TAIR SRAD Date Time Month Day Year Hour Minute
Now, I am wondoering how I can create a new dataset including the data of Feb 1 to Feb 10, 2015 from 13-19 (time) with average of each variable from all stations. In other words, for each 5 min interval I need the average of all variables instead of 9 variables associated with the 9 stations (ST). Like this:
Interval TAIR_ave SRAD_ave Date Time Month Day Year Hour Minute
I need to do it in SAS. It'd be really appreciated if you can help.
Best Regards,
Paalang

Related

Push Dataset in powerBI

I have a requirement where data from Event Hub is continuously coming to Stream Analytics and I am pushing it to POWERBI with a tumbling window of 15 mins.The Push data set will have data for a week.
The data is Transaction data where I have Amount and Transaction Date
For my requirement i need 3 charts
total Amount for today till current time ..SO suppose 04th Nov (6:41 pm) it is $100
change in Amount (Total Amount last week same day till same time- total Amount for today till current time) --Suppose last week it is 28 Oct till 6:41 pm it was #$80 so it should show #$20
KPI where it find percentage difference between first two. 20*100/100=20%
as I am using the tumbling window of 15 mins so i wont have transaction exactly till 6:41 but at least Amount where Max(Transaction Date)<= CurrentTime (6:41) for that day .
I am not sure how can I achieve 2nd and 3rd?
today = CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=TODAY()&&'Table'[datetime]<=NOW()))
total_last week = var lastweek=TODAY()-7 return CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=lastweek&&'Table'[datetime]<=NOW()-7))

Scheduling events by the week of the month, COLDFUSION

I'm trying to create a function, in Coldfusion, that will create an event by the Week of the Month, rather than by the Day of the Month.
An example would be that the event should be scheduled every 2nd week of a month, rather than the 2nd Tuesday of a month.
However, I've come across the problem that months can have anywhere from 4 to 6 weeks, and if someone scheduled an event on the 5th or 6th week of the month, it wouldn't repeat in the months that don't have 5 or 6 weeks.
I'm at a bit of a loss as to how to approach the problem, so any brainstorming advice would be greatly appreciated.
You'll need to find the lowest common denominator and that is February. February has 28 days when not leap year. A week has 7 days and 4 x 7 = 28 so that means you can not provide a function that reliably allows for scheduling on week 5 (or 6, 7, 8, etc) of every month. One work around would be that if there is no logical day for the scheduled week that month then run the task on the final day of the month or the first day of the following. On the last day for example you can check for any tasks scheduled later in the month that can not be run and then run them.

Number of sundays between two dates?

I am having problems with finding the number of sundays between two dates. I tried to use the intck () function to count number of weeks between two dates and since week in SAS starts on a Sunday I thought that was the right way. However now I am not so sure.
My dates go from 2007QI to 2013QII. I want to know the number of sundays in each quarter, so I have to look at the number of sundays between current quarter and previous (that is this date and lag (date)). When I use the intck() function I get 13 as the number of weeks in each quarter (except for one where I get 14).. i am not sure whether it is correct to assume that there are 13 sundays in each quarter?
intck is the correct function, but I would use weekday as the time interval. Ordinarily this assumes a 5 day working week, with Saturday and Sunday as weekends, but you can tweak it to use a 1 day working week, with Monday - Saturday as weekends (i.e. just count the number of Sundays).
data _null_;
format a b date9.;
a='01 nov 2016'd;
b='18 nov 2016'd;
Sundays = intck('weekday234567w',a,b);
put _all_;
run;

SAS aggregation seconds into minutes

I have data structured where for every second (YY-MM-DD-HH-MM-SS) I have actual car's speed. I want to aggregate my seconds into minutes (or 5, 10, 15 minutes) and have the average speed for that last minute (or 5,10,...).
Use proc timeseries, then choose your interval. For example, if you want to change it to 15 minute averages try
proc timeseries data = rawData output= minuteAvg;
id timestamp interval = Minute15 accumulate = avg;
run;
I've guessed the names of your time variable as you haven't supplied it. You can change the interval by suffixing the number of minutes to Minute (Minute1, Minute5, Minute10, etc.) or another interval keyword (Hour, Hour2, Hour12, Day, etc.).

Finding the day of the thirteenth of every month over a period of years

I am currently trying to solve some problems from the USACO training website in preparation for an unrelated C++ programming competition.
However, I am stuck on this problem:
Does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is non-negative and will not exceed 400.
The number N is provided in an input file and the output is to be a file with seven numbers in it, each representing the number of 13th's falling on a particular day of the week.
I was wondering how you guys would approach this problem. I am not looking for code or anything since that would just defeat the purpose of me doing this, instead just a starting point or an algorithm would be helpful.
So far the only thing I could think of is using the Doomsday Algorithm, however I am unsure about how I would implement that in code.
Any help would be greatly appreciated.
As Denny says, N is so small that you can easily iterate through the months using a table of days-in-a-month and a simple is-a-leap-year predicate to handle February. Just find out what day the 13th of Jan was in 1900 and then add up the elapsed days until 13th Feb, then 13th March etc.. Use a % operator to wrap the # of elapsed days back into a day-of-week value.
N is less than 400? well you just need to go over 365.25*400=146100 days at max. sounds easy to enumerate all of them, convert dates into year/month/date (with your favorite date conversion routine), testing for day of week is trivial.
I would precalculate the table though.
Just use brute force. Like this pseudocode example:
from datetime import date
day_names = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday']
counts = [0] * 7
for year in range(1900, 2300):
for month in range(1, 13):
counts[date(year, month, 13).weekday()] += 1
for day, count in zip(day_names, counts):
print('%s: %d' % (day, count))
The "hard" part is calculating the day of the week a date falls on. In C(++), you can use the mktime and localtime library functions if you know that your platform handles a large enough date range.