Adding cases by group in SAS - merge

I have an SAS dataset in a long format. The intervention program started from 2014 Spring semester, and it has been on until 2017 Spring semester. So there has been 7 semesters (2014 Spring and Fall, 2015 Spring and Fall, 2016 Spring and Fall, 2017 Spring).
Not everyone participated in all 7 semesters though. Some participated once and never came back, some participated more than twice but not necessarily two semesters in a low.
So each individual has a different number of cases. For someone who participated twice, for example, has 2 rows, some with 5 participations have 5 rows.
I want everyone has 7 rows in the dataset for some reason.
What could be the best way of programming to do this in SAS?
I would really appreciate any suggestions!

PROC EXPAND is probably the most direct way to do this, although it has the limitation that it won't extrapolate beyond the observed start/end of the range, and it expects regular intervals (or a lot more work to define intervals).
proc expand data=your_data out=expanded_data from=semiyear extrapolate method=none;
by student;
id semester_date;
run;
That relies on semester_date being a date variable corresponding generally to the start of each half-year.
Perhaps more easily in this case, you could use the printmiss option in proc tabulate, which would generate a table pretty easily.
ods output table=out_table;
proc tabulate data=your_data;
class student semester;
tables student,semester/printmiss misstext=' ';
run;
ods output close;
Then merge that back to the main dataset, this will have a row for every student*semester combination.

Related

Relative Date filtering Query Editor - Power BI

I don't understand the logic of Power Query Editor.
I have a big table with data from 2019 to 2024 (one column contains the monthly information).
I want to filter the data by the date of that column, but it has to be dynamic.
Two options:
The data I want to consider is "Current month -2". So all historical data minus current month.
The data I want to consider is a parameter extracted from somewhere (e.g. I set the latest month to consider manually somewhere in an Excel, which usually is "current month -1" but not always (best).
I would be happy with any of the two solutions.
Currently I found somewhere this formula which filters out vs last month:
= Table.SelectRows(#"Changed Type",each [Month]< Date.From(Date.StartOfMonth(DateTime.LocalNow())))
But somehow I do not find the way to go 2 months back.
Thanks a lot!
BR

TIBCO Spotfire: Cars in service since 3 weeks or more

I have a table of vehicles at service locations showing columns such as DAY, LICENSE, BOROUGH etc. I'd like to add a cross table showing the number of vehicles that have been serviced for 3 weeks or more. I'm not sure what custom expression to use.
Sample data:
Sample data
I hope your sample data isn't containing a bunch of legitmate license plates. not the most compromising data but I would recommend blacking out or replacing them with test data if it isn't already.
anyway. you're looking for the DateDiff() function. for example:
If(DateDiff('day', Date(DateTimeNow()), [Date]) >= 21, "21 days or more", "less than 21 days")

How to get only the first 6 months action of all my records

I'm pretty new in Tableau. I have looked at the forum already and the answered suggested. But I'm not quite sure it match my question.
I have a bunch of records. This is about registration for a sport lesson depending on time. All of them have a start date and and some of them a finish date. The other never finish (They continue until date T with T = now).
My goal is to compare only the first 6 months of all my records, I think there are 50 of them, like the evolution during this period of time. So, for some the start date would be in January 2009, for some other, it would be in May 2016, etc.
As field provided, I have the start date and the number of person that have subscribed those lesson through time.
So, do you if there is any to achieve this goal? Is there enough detail for you to understand what I am saying ?
Thx to you guys !!
EDIT
You can find enclosed a screenshot of the result that I already have.
number of registration for all lesson through time
I'm not sure to be clear, what I try to do is to compare the first 6 months only of each courses. So the evolution of the first 6 months of this course compare to the evolution of the first 6 months of this other course and so on :)
If I understand your question correctly you are wanting to show only the first six months of your data but you want this by each category.
I am assumuming that by definition this means 6 months from the first record in your data for each category.
In order to achieve this I would create a true/false flag using a level of detail expression. As you are new to tableau I would suggest you do some reading on this but basically you can force a calculation to be at a certain level of the data rather than at the row level. You use this to find the minimum date in the table and then use a date diff to return true if the actual date field is within 6 months of this.
Create a calculated field as follows:
[date] <= DATEADD('month', 6, { FIXED [category] :min([date])})
Then drag this onto your filters pane and select "TRUE". This should give you only the first six months of records for each category.
Let me know if you need anything else.

Should I break down a date field into month, day, and year in core data to easily group and fetch date by month and year?

How do I perform an equivalent of SQL extract/fetch records by month and year from a date in swift?
Two requirements are as follows:
List records by Month and Year
September 2015
October 2015
Display transactions falling under the Year and Month.
Edit: I do mean core data. Rephrased "equivalent in SQL" to equivalent of SQL" to clarify.
CoreData will store dates as doubles, which is the internal format for NSDate.
If you have a small database, just store the values as NSDate and filter based on that.
However, if you have a large database, you may want to denormalize your data a bit more.
You could store another field, say in "yyyymmdd" format, which gives you most of the filtering you require.
For finer grained control, you can also keep separate attributes for year, month, and day.
You may want to setup those fields as indexes as well, if you do lots of searching over vast amounts of data.
Remember, CoreData uses SQLite under the hood for most databases, but it's behavior characteristics are very different.
There is no universal "best" way, as it depends entirely on your data and how you use it.

UTC datetime offset

I need to get timestamps from Axapta-tables in TSQL, without timezone and / or daylight-bias-offsets for each time, eg from table JMGABSENCECALENDAR.
Taking this as initial approach, and regaring this, it works for current time. But reading data from the table referring to other timestamps, the solution provided in the second link doesn't get the information about daylight to the specified time.
For example:
I add an absence for today ( 2012-01-07 ).
Now, using SSMS, reading this dataset leads to
starttime = 2013-01-06 23:00:00.000
and endtime = 2013-01-07 23:00:00.000
That's ok, and I can use
DECLARE #UTCOffset SMALLINT
EXEC master..xp_regread
'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\Control\TimeZoneInformation',
'ActiveTimeBias',
#UTCOffset OUTPUT
SELECT DATEADD(MINUTE, #UTCOffset, GETDATE()) AS UTCTime
to remove offset. This works fine on actual dates, but what's the right way to remove offset for past or future times, eg 2012-07-01 ?
Here, the offset is 120 minutes, because of summertime. Reading Reg-Value only returns current offset.
The task has to be solved in TSQL 2008.
I had a same problem, but it was in a complete different setting. I had nothing to do with axapta.
However, i had the problem that i had to know the UTC offset of different times. The tricky part here is the fact that different countries use a different approach towards daylight saving times, and therefor a difference in the offset may occur for different countries at the same time.
What i did was to create a lookup table where i put in the dates that UTC offsets change, these are known dates. I gave it an offset column so i could easily look up the offset that i needed for a certain date, using the between operator.
It worked for me, maybe this solution can provide you something?
Ps. You don't have to lookup the UTC date offset from out of the registry. Using the function getutcdate() will give you the same ;) Using that inside a DATADD makes it a little more readable ;)
Have fun and i hope i could contribute to your problem...
Just because the daylight savings switch dates change from year to year and state to state, your only viable option is a lookup table.
You can find the data for example here http://www.timeanddate.com/time/dst/2013a.html
However, you might not have to maintain that list yourself. timeanddate.com has a calculator on their site. Others offer similar services. You could look for a public API and then use a few lines of CLR code to call that API from your database.
Or you could use such a service to maintain your own copy of that data. Having your own lookup table will be by far the fastest solution.