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?
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;
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?
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!!
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.
Thank you!!
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??
Also to find the date that's associated with that lowest value
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.
I did mark as solved and I will post a new question.
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.