BookmarkSubscribeRSS Feed
eh51
Calcite | Level 5

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. 

catTemperaturespeedweight
0.9300602
0.93050602
0.930501128
0.93019531128
0.95302161395
0.95302162339
0.95302162282
0.95302163226
0.95302164169
0.95302164113
0.9351978-564
0.9351974-621
0.9351968-677
0.953520371016
0.95352050959
0.95352062903
0.95352071846
0.95352079790
0.95352085734
0.95352090677
0.95352092621

 

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;

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

 

 

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

A few questions 

 

  1. I assume that the posted data set is the 'limits' data set. What does the 'Operations' data set look like?
  2. Given the two data sets 'limits' and 'operations', what does your desired result look like? A clear idea of what the desired result looks like makes it much easier to provide a usable code answer.
  3. Regarding the described logic: It seems you want to create a separate array for each distinct combination of Cat/Temperature, correct? If so, an array approach is definitely not the way to go because arrays are created during compilation of the data step. Since we probably do not know beforehand the combinations, we should go another way.

 

ballardw
Super User

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.

eh51
Calcite | Level 5

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. 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

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
  • 4 replies
  • 660 views
  • 0 likes
  • 4 in conversation