I would like to create several arrays (different sizes) from a dataset, but am not seeing how to do this in a data step. The first two columns hold the criteria for what goes in each array. The last two hold the data that does into the arrays.
I can create the arrays in IML easily, but the support material I find for arrays in a Data Step is focused on typing each array value into the program (which seems great for example work, but not typical work with large data). I would also like to change the source data set for different applications. For this reason, I do not want to type it into the program.
My program will update a variable in a data set of operating data. The flow is
1 Load the arrays from a 'limits' data set
2 For each observation in the 'operations' data set,
2a determine which array to use based on observation values
2b make a calculation based on an observation value and each row of the chosen array
2c write the result to a new variable in the operating data set
Maybe array use is not the best path. I am open to suggestions. Below is my attempt in IML space, but I do not know how to get a data step to recognize the IML arrays (tried submit/endsumit).
snippet of the source data set for the arrays.
each cat/temperature combination represents one array. There are 10 total.
cat Temperature speed weight 0.9 30 0 602 0.9 30 50 602 0.9 30 50 1128 0.9 30 1953 1128 0.95 30 2161 395 0.95 30 2162 339 0.95 30 2162 282 0.95 30 2163 226 0.95 30 2164 169 0.95 30 2164 113 0.9 35 1978 -564 0.9 35 1974 -621 0.9 35 1968 -677 0.95 35 2037 1016 0.95 35 2050 959 0.95 35 2062 903 0.95 35 2071 846 0.95 35 2079 790 0.95 35 2085 734 0.95 35 2090 677 0.95 35 2092 621
IML array creation (successful, but could not use later in program)
varNames = {"speed" "weight"};
use sasuser.limits; /* open data for reading */
read all var varNames into lim_35090 where(cat = 0.9 & temperature=35);
read all var varNames into lim_35095 where(cat = 0.95 & temperature=35);
read all var varNames into lim_30095 where(cat = 0.95 & temperature=30);
read all var varNames into lim_30110 where(cat = 1.1 & temperature=30);
others...
close sasuser.limits;
I'm not really seeing a need for arrays given the data you present (in fact, I don't see the need for them in IML either) and I would like you to explain a lot more what it is you are going to do with this data next, what analysis, what report, what statistical method? Give us an understanding of why you want this and what you are going to do with this. Don't talk in terms or arrays or anything else in SAS, just describe the analysis to be done.
Also, you say "the support material I find for arrays in a Data Step is focused on typing each array value into the program" ... well simple illustrative examples do that, but arrays can use data extracted from a database, no typing of values into the program.
A few questions
Arrays exist for the duration of a data step or Proc IML step. They do not persist as objects for use after that.
With out knowing how you intended to use these "not actually arrays" later it is very hard to make suggestions. It may be that you want to add variables that indicate if your conditions are met and use them to filter/summarize/model results later instead of physically sub-setting data.
Or use a WHERE statement or data step option to restrict analysis to those records.
I started a thread with the broader question that each of you are asking and will continue in that. I will retire this thread. Sorry for the confusion.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.