Trying to display names and dates of Iowa ships that have had least one battle in the year 1943 or later. However, every time I go to use date under the Battles table I can not compare it to a date ('YYYY-DD-MM').
This is what it keeps showing
You had to cast your string representation of date as actual date data type:
(π name σ class = 'Iowa' (Ships)) ⨝ (π date σ date > date('1943-01-01') (Battles))
Related
I have a data set that looks something like this:
Name birth birth_day death death_day
Don 1913 02-Mar 1998 01-Nov
Jack 1924 04-Dec 1970 13-Sep
I want to calculate the age of the people but I am confused as to how to format the entries in birth_day and death_day numerically so that I can subtract their birthdays from their death days to calculate their age. My professor suggested using the dmy function, so I did
x=dmy(day(birth_day), month(birth_day), birth);
However that did not work as planned. How can I go about resolving this problem?
In response to rambles:
data _null_;
set mydata;
death_date = input(cats(death_day,'-', death), date11.);
birth_date = input(cats(birth_day,'-', birth), date11.);
format death_date birth_date date11. age 4.1;
age = yrdif(birth_date, death_date,'AGE'); ** The 'AGE' part only works in SAS 9.3+!!;
put death_date= birth_date= age=;
run;
I tried something like this, however I ge an error at the line format death_date birth_date date11. age 4.1; saying ERROR 48-59: The format $DATE was not found or could not be loaded.
The following example mimics your first row:-
data example;
Name = "Don";
birth_day = "02-Mar";
birth = "1913";
death_day = "01-Nov";
death = "1998";
run;
data example_with_age;
set example;
length death_date birth_date 5 age 3;
format death_date birth_date date11. age 4.1;
death_date = input(cats(death_day,'-', death), date11.);
birth_date = input(cats(birth_day,'-', birth), date11.);
age = yrdif(birth_date, death_date,'AGE'); ** The 'AGE' part only works in SAS 9.3+!!;
run;
I've assumed your birth and death variables are character. If they're numeric, you should surround them with a put statement in the input rows.
I've been lazy with calcalating age by using a feature in newer versions of SAS - it's a surprising hassle calculating age when using full dates. If you're using an older SAS version, let me know in a comment and I'll add the older method of calculating the age.
How Can I display Month Name Instead of Month Number (Not Data Format Number) In Crystal Report?
The MonthName function can be used to display the name of the month, when you provide a number between 1 and 12 (1 being January). It is useful for showing the month name in Group titles or labeling groups in charts.
It can be combined with the DatePart function to return the month name of a variable or calculation.
Syntax
MonthName(month, abbr)
Month A number from 1 to 12.
abbr Optional.A Boolean value. If true, the month name is abbreviated. The default is false.
Examples
Example Result
MonthName(5) “May”
MonthName(10) “October”
MonthName(10,True) “Oct”
MonthName(DatePart(“m”, CurrentDate)) “October” when the current date is 10/5/10.
I have a column with data year&week. I would like to create a date axis based on this.
when i try to format the date, it is not working
I tried this:
var parseDate = d3.time.format("%Y-%W").parse;
d3.csv("temperatures_groups_2.csv", function(error, data) {
data.forEach(function(d,i) {
d.timestamp = parseDate(d.timestamp);
alert(d.timestamp);
d.temperature = +d.temperature;
}
});
i get null when the alert executes.
If i replace the same with d3.time.format("%Y-%m").parse, it works fine. It takes the month but not week no.
The csv contains data like this
timestamp,temperature
2013-01,19.5
2014-02,21.5
2015-03,20.5
2016-04,20.5
2017-05,21.25
The documentation says:
The following directives are not yet supported for parsing:
%U - week number of the year.
%W - week number of the year.
Hence you can't use D3 to parse these dates. You'll have to parse the date yourself or use another library, for example moment.js.
This works since version 3.2 and the documentation has been updated.
%U - week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
%W - week number of the year (Monday as the first day of the week) as a decimal number [00,53].
However, the format in your question won't work because the parser requires a specific date to be specified. E.g. by "%a". It would be nice to assume Sunday in the absence of a date specifier, but that's for another PR.
If I want to find the maximum value of a column from two states aggregated by a member's ID, should this work?
=Aggr(
MaxString(
Aggr(NODISTINCT MinString({[State1]}DATE_STRING),MBR_ID)
+
Aggr(NODISTINCT MinString({[State2]}DATE_STRING),MBR_ID)
) , MBR_ID)
So if I had this data:
MBR ID DATE_STRING
1 20120101
1 20120102
1 20120103
And State1 had 20120101 selected and State2 has 20120103 selected, my expression would return 20120103 for member 1.
Thanks!
Edit: In SQL, this would look like:
WITH MinInfo (DATE_STRING, MBR_ID)
AS (SELECT MIN(DATE_STRING), MBR_ID FROM Table WHERE TYPE IN ('State1', 'State2') GROUP BY MBR_ID, TYPE)
SELECT MAX(DATE_STRING) DATE_STRING, MBR_ID FROM MinInfo GROUP BY MBR_ID
It would be easier to accomplish your goal if you convert your that to an actual date field
Assuming that you are using a chart where MBR_ID is the Dimension, if you want the maximum date (latest date) you can do the following:
=nummax(Max({[State1]}DATE_STRING),Max({[State2]}DATE_STRING))
To convert to a date, you can use this function:
date#(DATE_STRING,'[text format of the date]')
(The date format looks like YYYYMMDD to me, but if its day then month, you would use YYYYDDMM)
I'd suggest you format it in the script, so that you wont have to worry about it every time you need to use that date.
I have an object which contains a list of due dates, I am trying to build a system which returns the due date when a specified date is 1 month or less before the due date. It should return the due date in this format "1st Feb 2009". Let me clarify, using my current code
#Build array of estate objects
estate.due_dates = "1st Feb, 3rd May, 1st Aug, 5th Nov"
estate2.due_dates = "28th Feb, 31st May, 31st Aug, 30th Nov"
estates = [estate,estate2]
set_due_date_on_estates("1st Jan 2009",estates) #Run function - should return "1st Feb 2009,28th Feb 2009"
def set_due_date_on_estates(date,estates)
estates.each{|estate|
estate.due_dates.split(",").each{|due_date|
((date)..(date >> 1)).each{|current_date|
estate.set_reminder(due_date + current_date.strftime("%Y")) if current_date.strftime('%d %m') ==
Date.parse(due_date).strftime('%d %m')
}
}
end
}
The issue I am having, is that my list of due dates doesnt have a Year, so I am looping through my range and checking if the dates are equal using the format "%d %m". If so I am setting the reminder in the estate object by using the current "due date" in the loop concatenated with the Year of the "current date" in the loop.
Am not too happy with the code, in particular the nested loops and wondered if there was a better way I could deal with checking that the due_dates where in the date range, even though the due_dates dont have a year. Thanks
You could use date parsers: Kronos, chronic
Example for kronos:
def parse_date(date)
Kronos.parse(date.sub(/\d{4}$/, ''))
end
This function gives you a Kronos object without year which is more easily to compare, build range and so on.
Yes you can use Chronic and also you can write a worker which will keep checking if the specified date is 1 month or less before the due date at regular interval. And ask that worker to do something if result is true (say send you an email or anything if date is within due date) you can find more information about worker by googling Resque and Redis. Another option would be to convert both dates on some base reference and then do the calculations.