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

Hi team, 

I have a dataset that looks like this: 

ID DIABETES CHF_FU DM_FU

1     1                  21            19

2     .                   10             .

3     1                  19            12. 

4     .                   19             .

5     1                   7              0

 

CHF_FU is the total follow-up time and DM_FU is the time that diabetes was diagnosed. I am trying to create a time-to-event data that has multiple columns per year of follow-up for diabetes. I used the following code: 

proc sort data = merged;
   by descending CHF_FU;
run;

data _NULL_;
   set merged;
   if _N_=1 then call symput('cols',CHF_FU);
run;

%put Additional Columns: &cols;

proc sort data = merged;   
   by ID;
run;

data merged1;
   set merged;

   array period[&cols];
   
   i = 1;
   do until (i > CHF_FU);
      period[i] = 0;
      i + 1;
   end;

   if not missing(DM_FU) then do j = DM_FU to CHF_FU;
      period[j] = 1;
   end;

   drop i j;
run;

It seems to be working for the first 4 rows but generates the error message 'Array subscript out of range' when it gets to the fifth row. The fifth row belongs to an individual that has diabetes but diabetes was present at baseline (hence the DM_FU of zero). 

I cannot figure out what the problem is. Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Change line:

if not missing(DM_FU) then do j = DM_FU to CHF_FU;

into:

if DM_FU > CHF_FU then do; 
   put '*** Data Error: DM_FU > CHF_FU';
   abort;
end;

if DM_FU>0 then do j = DM_FU to CHF_FU;

pay attention: zero is greater then missing and zero is not a vaild index;

 

Alternativley define an array of {&cols+1} and use index (i+1) in order

that base=0 will use index 1.

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

Change line:

if not missing(DM_FU) then do j = DM_FU to CHF_FU;

into:

if DM_FU > CHF_FU then do; 
   put '*** Data Error: DM_FU > CHF_FU';
   abort;
end;

if DM_FU>0 then do j = DM_FU to CHF_FU;

pay attention: zero is greater then missing and zero is not a vaild index;

 

Alternativley define an array of {&cols+1} and use index (i+1) in order

that base=0 will use index 1.

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!

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
  • 1 reply
  • 1742 views
  • 2 likes
  • 2 in conversation