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% |
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;
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;
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.