I have a question regarding to the intck function in SAS.
Can INTCK handle milliseconds? I read the SAS Community Posts, but it seems that it can only handle up to seconds. What should I do if I want to calculate the time difference in milliseconds?
I am also thinking directly subtracting one time from another, such as TIME_M - LAG_TIME. Will this work?
UPDATE:
It seems that directly subtract will work. My time is in the format of 9:00:01.321, where the 321 is the millisecond. It seems that 9:00:01.321 - 9:00:01.320 = 0.001.
I am just not sure if this method is official.
INTCK is most often used to calculate complex date and time intervals - i.e., date and time intervals that don't have a direct proportional relationship to the base date or time units (days and seconds, respectively). It can also be used to code more clearly (i.e., hours is directly proportional to seconds (*3600) but intck('HOUR',...) may be more clear).
As such, you're certainly welcome to add or subtract directly when using seconds or a proportion thereof (milliseconds would be one such proportion). That's how I would do it in my code.
You could also define a custom time interval if you wanted to take advantage of intck for a readability purpose.
Related
I have data about profits etc. and I want to count % increase/decrease from previous years (if there is one) for each year. Is there a better way to do that, than just do a specific calculated member for each year? My time dimension is server generated.
You could write a more generic calculated member that could work for Year and other levels on the time dimension.
You could use the Parallel Period mdx function to obtain the information for the previous sales. Then you can compare that to the current to get the percentage change.
I am a beginner in SAS and I have a data set of traffic incidents to analyse. I want to filter out the data by time of the day - all incidents before 18:00:00 . or incidents between 9:00:00 - 18:00:00
I have tried to find a suitable code, but have not had any success. Could anybody help out with this? Im using the standard SAS not enterprise guide.
Is it with a WHERE statement? if so, how do I input the time?
I assume from your description you have a data set with a time variable and want to subset it using a hard-coded time of day. For this, it's easiest to use a time literal with standard WHERE processing. A time literal is a time specified in quotes followed by the T character.
For example, you can create something similar to the following that will subset the times data set but only with observations where time is earlier than 18:00:
data times_before_6pm;
set times;
where time < '18:00't; /* restrict to times of day earlier than 6pm */
run;
This assumes your times are time values and not datetime values. If they are datetime values, you'll need to extract the time portion from it (using the TIMEPART() function, which you can do in the WHERE statement).
Hope this helps.
I am using AWS DynamoDB for storing time series data.
Accuracy is very important for this application. But, DynamoDB does not support native Date type to store.
I have two options:
Use UNIX Epoch Time
Use Date as string and store
Both options seem to have their problems:
The Epoch Time has the problem of leap seconds and losing accuracy.
The String Time type may have problems for sorting or querying between range of dates or times.
Which one should I use when accuracy is a key factor?
Use ISO format.
Stores milliseconds
Stores an optional timezone
Supports range queries for dates and date/time
Sample date formatted according to ISO 8601:
2016-12-02T00:52:34.256Z
I'm struggling a bit with a problem I can't quite get my head around.
Let's say we have a few columns;
IP-address, time stamp, SSN.
How would I go finding occurrences where the same IP appears in several records where the time is within the same one hour window (as an example of a window of time) and there are several SSNs.
This could for example be used for received applications for whatever, where we get a lot of traffic from one location where the data given varies.
Might lag or lead be good?
I'm using SAS, but only Proc SQL really. Might lag or lead be a way to go?
Thank you for the help!
There are some uncertainty in "one hour window" description. It depends when is your starting point - one hour from when?
Otherwise you could end up with a double cycle:
For every IP
For every timestamp
Check if other timestamps of the same IP exists between 1 hour and with different SSN
A simpler solution might be using lag function.
First sort by IP and time stamp.
Second use lag to calculated new column with time difference between each two rows. Flag it when it is less than 1 hour. Use this flag in next query grouping to identify distinct SSN.
Problem with latter solution that it will mark records that are beyond 1 hour window in total.
Sqlite has a different approach in storing time than other databases:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
**TEXT** as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
**REAL** as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
**INTEGER** as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
what is the best way to store date data in a sqlite database ?. TEXT, REAL or INTEGER ?
I'm interested in something like "using TEXT is space space consuming, using INTEGER is fine but you will have a big problem in the year 2038"
Integers are stored on 64 bits since SQLite 3.0 so year 2038 is not really a problem.
With REAL or INTEGER, you must perform calculations in fractions of days or fractions of seconds when you insert. With Integer, the resolution will be one second. With TEXT, it is one millisecond.
If you are concerned about total space and do not need any milliseconds or dates prior to 1970, then go for INTEGERs.
Is this correct?
Format Resolution Min Year Max Year Bytes/Date
Text Milliseconds 0 AD 9999 AD 23 or 46
Real Milliseconds? 4713 BC ???? 8
Integer Seconds 1970 AD ???? 8
The easiest way if you don't need fractions of seconds is epoch (integer number of seconds before or after 1970-01-01 00:00) accurate from -4714-11-24 until 5352-11-01 10:52:47
For calculation to human readable dates there is the function strftime