MrFlom
MrFlom

Reputation: 99

Reading in Datasets to Proc Optmodel

I have a dataset called zip5size that looks like this:

zip    district     volume  
22123  springfield  1234
10001  new york     567
20001  dc           8910
20005  dc           1112
10005  new york     1314

Where the zip and district variables are formatted as character and the volume variable is formatted as numeric.

I am trying to read the data into my proc optmodel code as follows:

proc optmodel;
  set <str> zips;
  set <str> districts;
  num volume;
  read data zip5size into zips=[zip] districts=[district] volume=volume;
quit;

I get the following error:

The target 'districts' must be numeric or string, found a set.

Why does SAS have no problem with the set zips and reading in the zip variable from my dataset, but it has a problem with the set districts and reading in the district variable from my dataset?

Upvotes: 0

Views: 949

Answers (1)

serge_k
serge_k

Reputation: 1772

In proc optmodel, set is the index-set. For example:

data dat; 
   input zip $ district $ volume;
datalines;
22123  springfield  1234
10001  new york      567
20001  dc           8910
20005  dc           1112
10005  new york     1314
;

proc optmodel;
  set <str> model_zips;
  set <str> model_dist;
  num vol_zips{model_zips};
  num vol_dist{model_dist};
  read data dat into model_zips=[zip] vol_zips=volume;
  read data dat into model_dist=[district] vol_dist=volume;
  print vol_zips;
  print vol_dist;
quit; 

will add to your model to arrays that are indexed by zip code and districts. Here is a good tutorial on how to model 1D and 2D variables.

Upvotes: 1

Related Questions