Quartz | Level 8

## defining arrays using values from other fields

In the table below I want to define an array basd on the start and end value (first two columns). The array for the first row is start 1 and end 5 so the array will go from 101% to 116% (dimension 5); the array for the second row will go from 102% to 108% (dimension 2) and so on.

can you create an array using the start and end variable names i.e.

array temp{*} price_start --price_end

 start end price_1 price_2 price_3 price_4 price_5 price_6 price_7 price_8 price_9 price_10 price_11 12 13 14 15 1 5 101% 102% 107% 108% 116% 120% 128% 130% 139% 140% 146% 152% 157% 164% 167% 2 3 101% 102% 108% 112% 114% 116% 122% 129% 133% 141% 146% 149% 158% 165% 172% 5 10 101% 102% 110% 114% 115% 122% 129% 132% 136% 144% 153% 161% 166% 168% 175% 12 14 101% 102% 108% 117% 127% 135% 144% 150% 155% 155% 157% 160% 162% 166% 170% 3 7 101% 102% 107% 114% 118% 126% 130% 132% 136% 138% 138% 147% 152% 158% 162% 5 8 101% 102% 111% 111% 120% 127% 129% 131% 137% 140% 149% 155% 162% 164% 173% 6 8 101% 102% 110% 119% 126% 132% 138% 140% 147% 150% 151% 152% 159% 160% 164%
1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: defining arrays using values from other fields

In a word, no.  Any arrays that you define must have exactly the same dimensions, for every observation.

What you can do is define an array that includes all the percent variables, and then process just a subset.  For example:

array all {*} price_: ;

do i=start to end;

* some logic that works with all{i};

end;

3 REPLIES 3
Opal | Level 21

## Re: defining arrays using values from other fields

In a word, no.  Any arrays that you define must have exactly the same dimensions, for every observation.

What you can do is define an array that includes all the percent variables, and then process just a subset.  For example:

array all {*} price_: ;

do i=start to end;

* some logic that works with all{i};

end;

Quartz | Level 8

## Re: defining arrays using values from other fields

Thanks astounding. I think that could work but is there a way of referencing the field name of variables in the array you want to exclude I.e. If number corresponding to field name is less than start than skip ... that kind of thing
Opal | Level 21

## Re: defining arrays using values from other fields

To some extent, that's what the posted code does.  The words START and END do not refer to the start and end of the array.  Rather, they refer to your DATA step variables START and END.  When START=5 and END=8, this means you will process the 5th through 8th variables using the DO loop.

If you want something more complex, it is possible to get the name of the variable as the loop proceeds.  For example, START=5, END=12, and you want to skip the variable price_10 while otherwise processing price_5 through price_12:

do i=start to end;

if upcase(vname(all{i})) ne 'PRICE_10' then ......

end;

I'm suspecting this is overkill and the original code is just what you are looking for.

Discussion stats
• 3 replies
• 782 views
• 0 likes
• 2 in conversation