Extracting/Selecting observations of the last 20 mins of a SAS data set

plnc

New Member
#1
Hey guys,

I hope anyone can help me on this.

I have a data set, which is continuously updated. For each observation, I have the time and date when the observations entered the data set. Currently I am calculating a number of metrics (means etc.) for the whole data set using a proc tabulate, which is working fine. However, I would like to perform my analysis not on the entire data set but only for the observations of the last 20 or 30 minutes from the moment, I request my metrics (System Time). Is there a way to include this restriction in a WHERE statement in the proc tabulate or is there a simple way to extract this time interval (last 20 min.) and create a new data set and then run the analysis?

I really appreciate your help.
Kind regards
 
#2
Yes, you can include a "where" clause as per the following template:
Code:
proc tabulate data = ... <options>;
	class ...;
	var ...;
	tables ...;
	where (<Selection criteria>);
run;
You could also use:
Code:
proc tabulate data = ... (where = (<Selection criteria>)) <options>;
	class ...;
	var ...;
	tables ...;
run;
The selection criteria you need could also be done in a macro if they are complicated, or you could use a macro to subset and to run your tabulation procedure only on those data that you would like.
 

plnc

New Member
#3
Thank you for the quick reply.
I think my explanation were a bit unclear. I know where to include a WHERE statement in a proc tabulate. I just don't know how to set the selection criteria to select only the observations from the last 20 or 30 mins according to their entry time (Variable: EntryTime format time10.). So the interval: my system time (or specified time) - 30 mins.
 
#4
Try this:
Code:
	where ((EntryTime+<Minutes>*60) > time());
“<Minutes>” is the cut-off time in minutes, e.g. 20 or 30 or whatever.

You can include the date as well if you’re worried about rollover at midnight.