Hello
I am trying to read raw data into SAS and need some help create age-related variables using information such as DOD, DOB, and age. According to the coding definition I was provided with for the variable "age":
Begins with:
0 or 1 = Years
2 = Months
3 = Days
4 = Hours
5 = Minutes
9 = Unknown (999)
Does anyone know how to create person's age at death based on the definition above? Ultimately, I'd like to subset people who died before they reach one year of age. I've attached some sample data. All three variables are numeric.
Thank you
So assuming we should just ignore the DOD and DOB, and just use AGE, why is there a problem? Do you need to come up with a fractional age for hours or minutes in the AGE field? Something like this should be straightforward:
if age < 200 then age_at_death = age;
else if age < 300 then age_at_death = (age-200)/12;
else if age < 900 then age_at_death=0;
This assumes that the data was entered somewhat intelligently.
21 = 21 years
201 = 1 month
Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... has instructions on making data step code from a SAS data set that can be posted here as text that we can use to create data to test code against.
Your data "explanation" is not very clear (and I'm not opening the xlsx).
The first step would be to read the date information into SAS date valued variables. If you have day, month and year values then the function MDY creates a SAS date value, or possibly the data can be read using an informat but we would have to see examples of what you have.
Once you have SAS dates for DOB and DOD it is very easy to get intervals, for example DOD-DOB would be number of days between birth and death. You may have to decide on a rule involving leap years though.
Any record with "unknown" is likely not going to allow an age calculation.
So if you have a DOB like 1211945, how do you know what date that is? It could be December 1, 1945, or it could be January 21, 1945.
Sorry- it should be MMDDYYYY
Still a problem. There is not indication that the month or the day is forced to be two digits.
Post a zip file would have had the same problem. That is why the instructions I posted start with a SAS DATA SET which would show us exactly what your current SAS data set looks like.
So assuming we should just ignore the DOD and DOB, and just use AGE, why is there a problem? Do you need to come up with a fractional age for hours or minutes in the AGE field? Something like this should be straightforward:
if age < 200 then age_at_death = age;
else if age < 300 then age_at_death = (age-200)/12;
else if age < 900 then age_at_death=0;
This assumes that the data was entered somewhat intelligently.
21 = 21 years
201 = 1 month
If you want a suggestion, you'll have to show the complete set of data points: what went in, what came out ... for observations that come up with the wrong calculations.
Makes sense- your previous comment actually helped me write code for creating age-related variables I initially needed. Thanks.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.