New Rules to validate US social security number(SSN) - algorithm

I need to validate US SSN number. Currently I have below rules:
Should be 9 digits long.
Not allowed are SSNs with all zeros in any digit group (000-xx-####, ###-00-####, ###-xx-0000).
Not allowed are SSNs with Area Numbers (First 3 digits) 000, 666 and 900-999.
Not allowed are SSNs from 987-65-4320 to 987-65-4329.
And there are few rules to validate Group Code(-xx-). I have verified in below Site but I couldn't understand the logic of "Group Code"?
http://www.codeproject.com/KB/validation/ssnvalidator.aspx

The SSA changed the rules for issuance of SSNs effective June 25, 2011. See http://www.ssa.gov/employer/randomization.html.
The rules for SSNs issued until the day before are outlined here: http://www.ssa.gov/employer/ssnweb.htm
I suppose that for SSNs to be accurately validated, you would need to know their issuance dates. Prior to June 25, 2011, use the old rules. On June 25, 2011 or after, use the new rules.

Related

Syntax for Sequential Variable Names

I am struggling to compile my large dataset and am assuming syntax commands are the answer, however, I am not skilled at all with syntax. My questions are specific to what syntax commands (or other methods) I should use to create hundreds/thousands of new variable names so I do not need to do it manually.
I am working with a dataset involving intimate partner homicides and domestic violence services utilization among victims from 2012-2021 (10 years), examined monthly (120 months). Across that timeframe, I have a three variable name set (REC [number of clients who received services], CALL [number of calls for services], HOUR [number of hours advocates/employees spent providing services]) that needs to be repeated monthly Jan-Dec across 10 years 2012-2021 and 39 separate services. See below:
MonthYear_REC_ServiceName
MonthYear_CALL_ServiceName
MonthYear_HOUR_ServiceName
"Month" in the above is Jan-Dec (01-12), "Year" is 2012-2021 (12-21), and "ServiceName" would be replaced with 39 different services. As an example for the year 2017 and "Shelter" services:
0117_REC_Shelter
0117_CALL_Shelter
0117_HOUR_Shelter
0217_REC_Shelter
0217_CALL_Shelter
0217_HOUR_Shelter
0317_REC_Shelter
0317_CALL_Shelter
0317_HOUR_Shelter
.....so on and so forth until December of 2017.
To further explain: This sequential monthly order would need to be repeated for each year in the 2012-2021 timeframe for each of 39 services for which I have data. "Shelter" services are shown as an example above, but I also need the same set of variable names across 38 other service types such as group counseling, legal advocacy, economic assistance, etc.
My overall question is (sorry for the repetition)- What syntax commands would I need to input to create this MASSIVE amount of variable names/variables? I hope this makes sense to everyone in the same way it makes sense to me! Sorry for the length and thank you in advance.
Best,
Shannon H.
Assuming what you want is to create an empty dataset with all the variable names you described, this will do it:
INPUT PROGRAM.
LOOP ind = 1 to (12*10*3*39).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.
do repeat vr=month year set service/vl=12 10 3 39.
compute vr=mod(ind,vl).
recode vr (0=vl).
compute ind=trunc((ind-1)/vl)+1.
end repeat.
compute year=year+11.
formats all (f2).
alter type month year (a2) set (a4).
compute month = char.lpad(ltrim(month), 2, "0").
recode set (" 1"="REC")(" 2"="CALL")(" 3"="HOUR").
* I suggest at this point you use "match files" to match the service numbers here with a list of service names.
* The following code creates fictitious service names instead to demonstrate how to use them.
string serviceName (a20) vrnm (a50).
compute serviceName=concat("service", char.lpad(ltrim(string(service, f2)), 2, "0") ).
* now to create the final variable names.
compute vrnm=concat(month, year, "_", set, "_", serviceNAme).
flip NEWNAMES = vrnm.
select if CASE_LBL="".
exe.

Is it possible to create a REDCap question that autofills based on previous answers?

I am working on a research project and I have an eligibility screener. I'd like to have a question at the end that is hidden from participants that shows "eligible - yes or no?" and autofills based on their questions to previous answers. Is this possible; if so, how could I set this up?
You would set this field up as a calculated field, hiding it as necessary, and build the arithmetic from your inclusion/exclusion criteria such that it returns 1 for eligible and 0 for ineligible. You can then use this 'eligible' value for later conditional logic, branching logic, automated survey invitations, and so on.
For example, say your eligibility requirements were that the participant is 18 years or older, does not have type-1 diabetes, and has a BMI greater than 30. Your calculated field would be something like:
if([age] >= 18 and [t1_diabetes] = '0' and [bmi] > 30, 1, 0)

How to validate a date in Xquery

If I have a date in YYYYMMDD format how to validate in Xquery version "1.0", so that it checks for month and year are valid and if say they are valid then a leap year with month as 02 can have a date 29 else a max 28.
Several integration tools such as Oracle Fusion Middleware implement Xquery version "1.0" not "3.0"
First of all, although your use case is rather simple: generally avoid tampering with dates (and especially times) on your own, and always rely on already implemented functionality, handling date and time is horribly complicated if you want to do it right.
Convert the string to a representation that XQuery's date functions are able to parse. If you can construct a date from the string, it is valid; if an error occurs, it is invalid. Dates can be constructed using xs:date($string). One way to convert the string would be using using substring(...) and string-join(...):
xs:date(string-join((substring($date, 1, 4), substring($date, 5, 2), substring($date, 7, 2)), '-'))
To catch an error, use a try/catch block.

to get selective content using xpath

<li>
Chemistry In-House Symposium 2014 (CiHS-2014)
<br>
In 2011, Chemistry In-House Symposium (CiHS) was initiated as department yearly event on the occasion of the International Year of Chemistry and Golden Jubilee Year of the Department. The theme of the CiHS is to provide the platform for the deliberation of exciting research findings and mutual exchange of ideas within the Department. This yearly event, in addition, is expected to provide an opportunity for further enhancing the collaborative research within the department. This year, the CiHS will be organized on the Wednesday, August 13, 2014 at IC & SR auditorium, IIT Madras.
<br>
<strong>Venue:</strong>
IC & SR auditorium, IIT Madras
<br>
<strong>Dates:</strong>
Aug 13, 2014 to Aug 13, 2014
<br>
<strong>Coordinator(s):</strong>
Ramesh Gardas
</li>
I need to write an xpath for the above script in which i should be able to get only the text of 'a' tag,dates and venue. I do not want the entire description.Is there any way we can get only selective text using the xpath=> //div[#class='block-inner clearfix']/ul/li//text()
To get the text within the a element you can simply execute
//div[#class='block-inner clearfix']/ul/li/a/text()
To get the text, which immediately follows the specified <strong/> element you can use the following XPath:
//div[#class='block-inner clearfix']/ul/li/text()[preceding-sibling::strong = "Dates:"][1]
To get the venue, use respectively
//div[#class='block-inner clearfix']/ul/li/text()[preceding-sibling::strong = "Venue:"][1]

Why does Ruby think there are 366 days in 100 AD?

The following expression returns '366' in Ruby, implying 100 AD is a leap year (which it is not):
(Date.ordinal(101) - Date.ordinal(100)).to_i
Same with DateTime.
However, Date.leap?(100) correctly returns false.
Same results for version 1.9.1. and 2.0.0.
What gives? Should I file a bug report?
Update
Also, apparenly 1582 AD is 10 days short!
(Date.ordinal(1583) - Date.ordinal(1582)).to_i
=> 355
According to Wikipedia, 100 was indeed a leap year and 1582 did indeed skip 10 days.
Apparently, prior to 1582-10-15, Ruby interprets dates as Julian calendar dates, instead of Gregorian calendar dates. More details here:
http://teleologi.blogspot.com/2013/05/ruby-times-dates-good-bad-and-so-on.html
Apparently not a bug, but definitely violates the principle of least surprise (at least in the eyes of this coder).
How confusing!
Edit
Debate about "reasonable defaults" aside, Ruby seems to quite flexible on these touchy issues of calendar-choice, compared to other languages. I've learned that the Date and DateTime constructors can receive a "reform date" constant, which determines when the transition from Julian to Gregorian calendar occurs. The default is ITALY (1582-10-15), but ENGLAND is also an option (the jump occurs at 1752-09-14).
To avoid surprises from transitioning between calendars, I should have used the Gregorian calendar for all dates:
(Date.ordinal(i+1,1,Date::GREGORIAN) - Date.ordinal(i,1,Date::GREGORIAN)).to_i
=> 365
Also, Date.leap?(100) returned "false" because it is an alias of Date.gregorian_leap?. Meanwhile, Date.julian_leap(100) returns true. To avoid surprises, probably best to use method version of leap?, which uses whichever reform date you've picked.
Date.new(100, 1, 1, Date::JULIAN).leap?
=> true
Date.new(100, 1, 1, Date::GREGORIAN).leap?
=> false

Resources