Hello everyone,
I'm try to use array to transpose long to wide format. However, the log shows "ERRO: Array subscript out of range at line 1602 column 8." Could you please tell me where the problem is?
Thank you so much!
1586 data test;
1587 set C1_10;
1588 by casid;
1589
1590 retain
1591 ACEMED1-ACEMED6 ACEMED8 ACEMED10;
1592
1593 array aACEMED{8} ACEMED1-ACEMED6 ACEMED8 ACEMED10;
1594
1595
1596 if first.casid then do;
1597 do i=1 to 8;
1598 aACEMED{i}=.;
1599 end;
1600 end;
1601
1602 aACEMED{EXAMN}=ACEMED;
1603
1604 if last.casid then output;
1605
1606 keep casid
1607 ACEMED1-ACEMED6 ACEMED8 ACEMED10;
1608
1609 run;
ERROR: Array subscript out of range at line 1602 column 8.
CASID=7 WT=62 GHB=7.4 TOALC=0 SMEVR=1 SMNOW=0 NHTN=0 TCHOL=245 HDL=45 TRIG=158 LDL=168
AGE=44.07118412 DUR=30.71321013 SBP=109 DBP=60 THENAER=2.625374813 EXAMN=10 WHR=0.857580398
BMI=23.77095534 LVEDU=3 HINYR=1 TOTUNI=50 MARST=3 FHHBP=1 WBC=4.5 REABP=0 ACEMED=0 LIPMED=0
GFRCG=100.3226373 ESTGDR=8.824056209 Fromcycle=10 DCCTA1c=7.7407407407 totuniwt=0.8064516129
observed=1 FIRST.CASID=0 LAST.CASID=1 ACEMED1=0 ACEMED2=0 ACEMED3=0 ACEMED4=0 ACEMED5=0
ACEMED6=0 ACEMED8=. ACEMED10=0 i=. _ERROR_=1 _N_=8
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 9 observations read from the data set WORK.C1_10.
WARNING: The data set WORK.TEST may be incomplete. When this step was stopped there were 0
observations and 9 variables.
WARNING: Data set WORK.TEST was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
When you define an array with N elements , the array reference cannot be outside that range i.e For example, should N be 10, the lower bound is always 1 and upper bound is 10. If you happen to reference the array with number say 12 or 0, that implies out of range
Also please do not confuse with number suffix as an indicator of number of elements in an array
Hello @Vivian_Vivian Did you notice in your log- EXAMN=10 while you have only 8 elements in your array? I guess that says it
ERROR: Array subscript out of range at line 1602 column 8.
CASID=7 WT=62 GHB=7.4 TOALC=0 SMEVR=1 SMNOW=0 NHTN=0 TCHOL=245 HDL=45 TRIG=158 LDL=168
AGE=44.07118412 DUR=30.71321013 SBP=109 DBP=60 THENAER=2.625374813 EXAMN=10
Thanks for your reply @novinosrin . I only have 8 exams in total (Exam1-EXAM6 EXAM8 EXAM10). The EXAM7 and EXAM9 are missing for every ID in the data set.
so of course you can't use the variable EXAMN as array index
Do you mean the array index EXAMN has to be continuous integral numbers without skips?
When you define an array with N elements , the array reference cannot be outside that range i.e For example, should N be 10, the lower bound is always 1 and upper bound is 10. If you happen to reference the array with number say 12 or 0, that implies out of range
Also please do not confuse with number suffix as an indicator of number of elements in an array
Got it! thanks a lot ! @novinosrin
@Vivian_Vivian wrote:
Thanks for your reply @novinosrin . I only have 8 exams in total (Exam1-EXAM6 EXAM8 EXAM10). The EXAM7 and EXAM9 are missing for every ID in the data set.
Why not just define the array using EXAM1-EXAM10 anyway?
Then the index into the array will match the suffix on the variable name.
You can always drop the EXAM7 and EXAM9 variables if you don't need them.
Yes! That's what I did and it worked out! Thanks for your reply
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.