BookmarkSubscribeRSS Feed
spg
Obsidian | Level 7 spg
Obsidian | Level 7

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

FAMILYMEM1MEM2MEM3MEM4MEM5MEM6MEM7
0012/1/19419/1/20002/1/2004....
0026/1/1989......
0038/1/19638/1/1963.....
0049/1/19946/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!

4 REPLIES 4
ballardw
Super User

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);

Tom
Super User Tom
Super User

The error message is because the name of the array was AGE_MEM and not MEM.

Look at this thread for how to calculate age. 

Also you probably do not want the OUTPUT statement.  Unless you also want to rotate the data into a vertical format.

spg
Obsidian | Level 7 spg
Obsidian | Level 7

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 4 replies
  • 918 views
  • 0 likes
  • 4 in conversation