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

When I ran the array codes the log says

ERROR: array subscript out of range at line 865 column 4.

Are some of my variables not in the right format?

Ksharp
Super User

use VVALUEX() funtion.

 

data have;
input var1   var1_date : mmddyy10.  num2   num2_date : mmddyy10.    cd4_3     cd4_3date  : mmddyy10.;
format var1_date num2_date   cd4_3date  mmddyy10.;
cards;
200    08/09/16     300      05/02/16       400        06/10/15       500    01/20/15   .......    350     02/15/05
250    07/06/16     200      04/10/14 . .
100    01/02/17     150      06/01/15       550        02/10/15   
;
run;
data want;
 set have;
 array x{*} var1 num2 cd4_3;
 idx=whichn(min(of x{*}),of x{*});
 min_date=vvaluex(cats(vname(x{idx}),'_date'));
run;
michan22
Quartz | Level 8

Thanks for the advice!

I created new variables for both the numerical and date variables so that they are in order (newcd4_1-newcd4_17 and newcd4date_1-newcd4date_17).

I put:

array x{*} newcd4_1-newcd4_17;

idx=whichn(min(of x{*}),of x{*});

min_date=vvaluex(cats(vname(x{idx}),'_date'));

run;

 

log says 

argument to function VVALUEX is not a known variable name: newcd4_17_date.

I think it's _date not matching the new variables I created?

michan22
Quartz | Level 8

I changed the date variable names to .... _date and it worked!

Can you tell me what vvaluex function does and what does this line do exactly?

 

min_date=vvaluex(cats(vname(x{idx}),'_date'));

Thank you so much!!

Ksharp
Super User
cats(vname(x{idx}),'_date')

will get string "var1_date" (var1 has the min value).

vvaluex("var1_date") means get the value of variable var1_date.

michan22
Quartz | Level 8

I have one more question relating to this dataset:

I want to find the lowest numerical value for each observation. I also have an additional variable called diagnosis date, and I only want to accept the lowest value for each observation if the date that linked to the numerical value is before the diagnosis date.

How can I proceed to do that? add if then do loop to the array??

michan22
Quartz | Level 8

Also to find the date that's associated with that lowest value 

Reeza
Super User

I think st this point you should mark this question as answered and post a new question. Please mark the correct solution as the answer. 

michan22
Quartz | Level 8

I did mark as solved and I will post a new question.

Thank you!

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 24 replies
  • 3007 views
  • 3 likes
  • 5 in conversation