BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jhs2171
Obsidian | Level 7

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

View solution in original post

9 REPLIES 9
ballardw
Super User

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.

jhs2171
Obsidian | Level 7
 
Astounding
PROC Star

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.

jhs2171
Obsidian | Level 7

Sorry- it should be MMDDYYYY 

ballardw
Super User

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.

Astounding
PROC Star

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

jhs2171
Obsidian | Level 7
 
Astounding
PROC Star

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.

jhs2171
Obsidian | Level 7

Makes sense- your previous comment actually helped me write code for creating age-related variables I initially needed. Thanks. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1467 views
  • 0 likes
  • 3 in conversation