Flagging Lines Below HHMM Threshold SAS IF/THEN Data Statement - if-statement

I have a dataset where I calculated the number of total hours it took to process a request in hours. A request should be completed in 72 hours, or else if an extension is requested a request should be completed in 408 hours (14 days plus 72 hours).
I need to flag values with a Y or N depending if they meet these criteria.
My problem is that it is only recognizing negative HHMM values as below threshold, not a value like 29:15 which would represent 29 hours 15 minutes. This is less than 72 hours and should be marked "Y" indicating it is timely, but it is marking it "N".
This is what I tried so far:
data work.tbl_6;
set work.tbl_6;
if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= 72 then notification_timely="Y";
else if was_a_timeframe_extension_taken_ = "Y" and time_to_notification <= 408 then notification_timely="Y";
else notification_timely="N";
run;
Can someone advise what could be going wrong here?

This assumes you have data as a SAS time. If you do not you'll need to use INPUT() to do some conversions.
You need to specify time values using the t after to specify a time constant.
if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= '72:00't then notification_timely="Y";
SAS stores times as the number of second so you could also convert 72 hours to the number of seconds and use that value.
if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= (72*60*60) then notification_timely="Y";
EDIT:
In general, this style of programming is dangerous and makes it harder to debug your code. If you can avoid it, I would highly recommend it. Instead, give each data set a unique name or keep adding to the previous data step.
data work.tbl_6;
set work.tbl_6;

Related

How can I generate a time stamp every time an event happens (DAX)?

DAX is still kinda new to me and I just can't figure out a way of generating and saving a timestamp every time a event happens. Let me be more clear. I have a column that contains the sequence number of an operation. When the table updates, the Sequence number may goes forward or stay the same. Whenever this sequence number goes above 45, I want to save the TIMESTAMP - NOW().
The table is like this:
ORDER ID
SEQUENCE NUMBER
245677
10
245678
5
245679
50
WHEN THE TABLE UPDATES ->
ORDER ID
SEQUENCE NUMBER
245677
49
245678
15
245679
90
I need to save the timestamps of those events (sequence number going above 45), creating a calculated column (or any other solution) that should look like this:
ORDER ID
SEQUENCE NUMBER
TIMESTAMP
245677
49
23/11/2022 - 08AM
245678
15
VOID or random old date (the event havent occured yet)
245679
90
22/11/2022 - 15PM
I tried this code but it refreshes every second after the event happened
IF ( 'local of orders'[SEQUENCE NUMBER] > 45,
NOW(),01/01/2000)
Could anyone please help?

Checking the time in ORACLE APEX 5.1

I'm am new to apex and I'm working on a food ordering application where customers are permitted to change their order details only up to 15 minutes after the order has been placed. How can I implement that ?
Create a validation on date item. Calculate difference between SYSDATE (i.e. "now") and order date. Subtracting two DATE datatype values results in number of days, so multiply it by 24 (to get hours) and by 60 (to get minutes). If that result is more than 15, raise an error.
To provide an alternative to Littlefoot's answer, timestamp arithmetic returns interval literals, if you use SYSTIMESTAMP instead your query could be:
systimestamp - order_date < interval '15' minute
or, even using SYSDATE something like:
order_date > sysdate - interval '15' minute
One note, the 15 minutes seems somewhat arbitrary (a magic number) it relies on the order not starting to be processed within that time limit. It feels more natural to say something like "you can change your order until the kitchen has started cooking it". There's no need for any magic numbers then and considerably less wastage (either of the customers time always waiting 15 minutes or of the kitchen's resources cooking something they may then have to discard).

SAS group rows based on time intervals

I am doing some analysis on a dataset with a variable named "time". The time is in the format of HH:MM:SS.
However, now I want to group the rows based on 5 secs and 1 min time intervals respectively in two different analysis.
I checked some StackOverflow posts online, but it seems that they used a variable called "Interval" which starts at 1 and increases when the interval ends.
data _quotes_interval;
set _quotes_processed;
interval = intck('MINUTE1',"09:30:00"t,time)+1;
run;
What I want to do is to keep the time format. For example, if the original time is 9:00:30, and I am doing the 1 min interval, I want to change the time to 9:00:00 instead.
Is there a way to do this?
SAS stores time as the number of seconds. Since you want to round to the nearest minute or 5 minute, a translation would be, 5*60 = 300 & 60 seconds. The SAS round function supports this.
time_nearest_minute = round(time, 60);
time_nearest_minute5 = round(time, 300);
Edit based on comment:
Time_nearest_second5 = round(time, 5);
For the processing by minute, you can use
data _quotes_interval / view = _quotes_interval;
set _quotes_processed;
interval = intnx('MINUTE', time, 0, 'begin');
run;
intnx is by default used to add or substract time intervals. Here I add 0 binutes, but that is just because I need the function for its fourth parameter, which specifies to go back to the 'begin' of the interval of 1 minute.
PS: For preformance reasons, I would use the view= option, to create a view on the existing data instead of copying all data.
For processing by 5 second intervals
try interval = intnx('SECOND5', time, 0, 'begin');
Disclaimer:
I do not have SAS on this computer. If it does not work, react in a comment and I will test it at work.

Fast Update For a Table

I need to update CustomerValue table for 4000 customers for 20 different options.
It exactly comes out to 80,000 records.
I wrote this:
Update CustomerValue Set Value = 100 where Option in
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
But it is taking time. I was wondering If I can use PL/SQL block or any other way to make it run faster. Few minutes are okay....It ran for 11 minutes so I cancelled it.
Note: There is no ROWID in that table.
Thanks
If your condition is regular like this
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
1100000 rows 6 second.
UPDATE CustomerValue
SET DEGER = 100
WHERE Value >= 1 AND Value <=20

How to record total values with rrdtool

I'm pretty sure this question has been asked several times, but either I did not find the correct answer or I didn't understand the solution.
To my current problem:
I have a sensor which measures the time a motor is running.
The sensor is reset after reading.
I'm not interested in the time the motor was running the last five minutes.
I'm more interested in how long the motor was running from the very beginning (or from the last reset).
When storing the values in an rrd, depending on the aggregate function, several values are recorded.
When working with GAUGE, the value read is 3000 (10th seconds) every five minutes.
When working with ABSOLUTE, the value is 10 every five minutes.
But what I would like to get is something like:
3000 after the first 5 minutes
6000 after the next 5 minutes (last value + 3000)
9000 after another 5 minutes (last value + 3000)
The accuracy of the older values (and slopes) is not so important, but the last value should reflect the time in seconds since the beginning as accurate as possible.
Is there a way to accomplish this?
I dont know if it is useful for ur need or not but maybe using TREND/TRENDNAN CDEF function is what u want, look at here:
TREND CDEF function
I now created a small SQLite database with one table and one column in that tabe.
The table has one row. I update that row every time my cron job runs and add the current value to the current value. So the current value of the one row and column is the cumualted value of my sensor. This is then fed into the rrd.
Any other (better) ideas?
The way that I'd tackle this (in Linux) is to write the value to a plain-text file and then use the value from that file for the RRDTool graph. I think that maybe using SQLite (or any other SQL server) just to keep track of this would be unnecessarily hard on a system just to keep track of something like this.