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
PROC Star

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
PROC Star

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
PROC Star

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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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