BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
brophymj
Quartz | Level 8

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

 

 

startendprice_1price_2price_3price_4price_5price_6price_7price_8price_9price_10price_1112131415
15101%102%107%108%116%120%128%130%139%140%146%152%157%164%167%
23101%102%108%112%114%116%122%129%133%141%146%149%158%165%172%
510101%102%110%114%115%122%129%132%136%144%153%161%166%168%175%
1214101%102%108%117%127%135%144%150%155%155%157%160%162%166%170%
37101%102%107%114%118%126%130%132%136%138%138%147%152%158%162%
58101%102%111%111%120%127%129%131%137%140%149%155%162%164%173%
68101%102%110%119%126%132%138%140%147%150%151%152%159%160%164%
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
Opal | Level 21

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;

View solution in original post

3 REPLIES 3
Astounding
Opal | Level 21

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;

brophymj
Quartz | Level 8
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
Astounding
Opal | Level 21

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

What is Bayesian Analysis?

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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