BookmarkSubscribeRSS Feed
error_prone
Barite | Level 11
Read the documentation of array statement, it explains how to define an array. If you want a list of variables to be mapped by an array, you have to list every variable if they don't have the same prefix and end with a number.
devsas
Pyrite | Level 9

I did read it and tried to follow that, and this is what I have come up so far. I appreciate your response, but its not really helpful. Its only when I hit the wall after trying all methods, I come here as I understand everyone's time is precious.

Reeza
Super User

As @error_prone mentioned you need to list all the variables for an array. 

 

You can use variable lists, but your definition isn’t a valid variable list. 

See the variable list requirements here. 

 

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&docsetVer...

devsas
Pyrite | Level 9

I believe in this case there is no clean way to define them in arrays since variable names are so different and if I have to write 8 statements to define each difference, what's the point of arrays here. Sorry its beyond me.

devsas
Pyrite | Level 9

Ok, so I finally got it, though im not sure this is the most efficient way as there is so much typing still involved.

  data test;
set fish2_;
array all{*} hg n elv sa z da rf fr;
array all_mean{*} hg_mean n_mean elv_mean sa_mean z_mean da_mean rf_mean fr_mean ;
array all_median{*} hg_median n_median elv_median sa_median z_median da_median rf_median fr_median ;
array diff{*} hg_diff n_diff elv_diff sa_diff z_diff da_diff rf_diff fr_diff  ;
array diffM{*} hg_diff_me n_diff_me elv_diff_me sa_diff_me z_diff_me da_diff_me rf_diff_me fr_diff_me ;
do i=1 to dim(all);
diff[i]= all_mean{i} - all{i};
diffM[i]= all_median{i} - all{i};
end;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 19 replies
  • 3313 views
  • 4 likes
  • 5 in conversation