SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
AaronTram
Calcite | Level 5

I have a cohort of 100,000+ subjects with ID, DOB, DiagnosisDate, DeathDate and I am trying to tally up person time by age intervals using the DiagnosisDate as the start date. The purpose is to compare to other summary population data on mortality (e.g. CDC NCHS). So, I am trying to create a table like the image included below. 

 

I am having trouble using SAS (EG version 7.15) arrays and macros that I think are the best way to create such a table. 

 

 

Here's the code I am using: 

 

 

DATA work.test;
	SET (working dataset)

	ARRAY ptage ptage020-ptage125; *Creates person time variables for each age of interest;

	x = yrdif(DOB,DiagnosisDate,'act/act');
	age_start = int(x);
	y = yrdif(DOB,DeathDate,'act/act');
	age_end = int(y);

	DO i = age_start to age_end;
		IF age_start = i THEN ptage(i) = i+1-x;
		IF age_start LT i LT age_end THEN ptage(i)=1;
		IF age_start = age_end THEN ptage(i) = y-x;
		IF age_start NE age_end AND age_end = i THEN ptage(i) = 1-(ceil(y)-y);
	END;
RUN;

 

I am mostly getting an "array subscript out of range" error. This is occurring on an observation with the age_start and age_end both of 108, so I'm not sure if it is due to the way the array is referenced (variable names ending in numbers that span from 20 to 125) or from the way it is handing observations where age-start = age_end.

 

My plan is to use the array variables (ptage20-125, PT signifies person time) and PROC SUMMARY to add up the person time in the cohort for each age. If there is an easier way... please share.

 

Many thanks -- Aaron

 

 

 

 

Picture1.jpg

 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

Do you realise that the way you built your array,  PTAGE[21]  is  PTAGE040  ?

Is that what you want?

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 790 views
  • 0 likes
  • 2 in conversation