Reputation: 15
I am trying to concatenate multiple columns bases on condition. Data is as follows.
CRN Diff Pay1 Pay2 Pay3 Pay4 Pay5 Pay6 Pay7 Pay8 Pay9 Pay10
1 1 000 084 084 084 000 XXX 000 XXX XXX XXX
2 10 065 000 000 000 000 XXX XXX XXX XXX XXX
3 -1 000 XXX XXX XXX XXX XXX XXX XXX XXX XXX
4 3 XXX 000 000 000 000 000 000 000 000 000
5 -2 070 070 070 070 070 070 070 XXX XXX XXX
6 1 090 XXX XXX XXX XXX XXX XXX XXX XXX XXX
The code I am using is as follows.
data temp;
set temp;
format hist $200.;
array col(*) Pay1-Pay10;
if diff=-1 then hist=catx('',col(2-10));
else if diff=-2 then hist=catx('',col(3-10));
else hist=catx('',col(*));
run;
I want concatenate column based on diff=-1 , -2 etc and concat corresponding columns.
The error I am getting is "array subscript out of range". Please help.
Upvotes: 1
Views: 686
Reputation: 51611
Your array definition does not allow the use of either -8 or -7 as an index. Only integers between 1 and 10. But it does not look like you need to define or use an array at all.
Just use variable lists instead. Make sure to use the OF
keyword when passing a list of variables to a function.
if diff=-1 then hist=catx(' ',of pay2-pay10);
else if diff=-2 then hist=catx(' ',of pay3-pay10);
else hist=catx(' ',of pay1-pay10);
Upvotes: 1