Hi,
I'm trying to write a code that will calculate ages of all members of a family (MEM1 to MEM7) from their dob. My data looks like this
FAMILY | MEM1 | MEM2 | MEM3 | MEM4 | MEM5 | MEM6 | MEM7 |
001 | 2/1/1941 | 9/1/2000 | 2/1/2004 | . | . | . | . |
002 | 6/1/1989 | . | . | . | . | . | . |
003 | 8/1/1963 | 8/1/1963 | . | . | . | . | . |
004 | 9/1/1994 | 6/1/2000 | . | . | . | . | . |
When I run the following code, it says MEMi variable is uninitialized. Please help.
data a;
set b ;
array age {7} age1-age7;
array age_mem {7} age_mem1-age_mem7;
do i=1 to 7;
age(i)=floor( (intck('month', MEM(i), '01jan2013'd) -(day('01jan2013'd) < day(MEM(i))))/12);
age_mem(i)= age(i)-(floor( (intck('month', MEM(i), '01jan2013'd) -(day('01jan2013'd) < min(day(MEM(i)), day(intnx('month','01jan2013'd,1) -1)))/12)));
output;
end;
run;
Thanks!
Looks like you need an additional array:
array mem mem1-mem7;
and [] instead of () usually
so
age(i)=floor( (intck('month', MEM, '01jan2013'd) -(day('01jan2013'd) < day(MEM(i))))/12);
should be
age=floor( (intck('month', MEM, '01jan2013'd) -(day('01jan2013'd) < day(MEM)))/12);
see also:
http://www.sascommunity.org/wiki/Tips:Calculating_Exact_Age_with_the_YRDIF_Function
Ron Fehd sasComm.org maven
Hey! Thanks for the tips on the age calculation facility in SAS 9.3. I do have that version and will make use of it towards this end.
Thanks again, all. I alsofixed the code to make it run now.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.