Like a previous poster, I'm trying to get a 3D data into PROC OPTMODEL. This is my first foray into optimization and OPTMODEL so I'm sure I'm making many beginner mistakes.
Here's the problem:
I have a dataset with four variables: Camera, Orientation, Target, k.
For each observation, k is 1 if Target (t) is in the field of view of Orientation (r) of Camera (c); else, k is 0.
There are 22 Cameras each with 8 possible Orientations available to cover 49 Gridpoints for a total of 8624 observations.
How can I get this dataset into a 3D array (I'm calling it Matrix {CAMERAS, ORIENTATIONS, TARGETS} populated with the binary k values for optimization by Proc OPTMODEL and indexed by CAMERAS, ORIENTATIONS and TARGETS?
Below is the code that I've developed so far together with a few lines of the dataset work.coveragematrix. In the code provided, I first read ID's for CAMERAS from a separate dataset (work.cameraorientations), hardcode the 8 possible ORIENTATIONS, and read the ID codes for TARGETS from the data step at the beginning of the code. Next I establish the new array MATRIX which is to be filled with k-values from dataset work.coveragematrix. This is where things go horribly wrong.
/* Create data for Targets: 7x7 matrix of gridpoints is 49 total*/
data targets(drop=i);
do i=1 to 49;
gridpoint=i;
output;
end;
Proc optmodel;
/* Read CoverageMatrix data into index sets*/
set <str> CAMERAS;
read data work.cameraorientations into CAMERAS=[station];
set <str> ORIENTATIONS=/'NHI' 'NLO' 'EHI' 'ELO' 'SHO' 'SLO' 'WHI' 'WLO'/;
set <num> TARGETS;
num Matrix {CAMERAS, ORIENTATIONS, TARGETS};
read data work.CoverageMatrix into MATRIX= {c in CAMERAS, r in ORIENTATIONS, t in TARGETS}
print matrix;
quit;
Below is the log output, together with a snippet of work.coveragematrix
Thanks in advance for any guidance.
Regards,
Gene
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 /* Create data for Targets: 7x7 matrix of gridpoints is 49 total*/
74 data targets(drop=i);
75 do i=1 to 49;
76 gridpoint=i;
77 output;
78 end;
NOTE: The data set WORK.TARGETS has 49 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 661.31k
OS Memory 33964.00k
Timestamp 03/25/2021 06:25:52 PM
Step Count 57 Switch Count 2
Page Faults 0
Page Reclaims 147
Page Swaps 0
Voluntary Context Switches 10
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
79 Proc optmodel;
80 /* Read CoverageMatrix data into index sets*/
81 set <str> CAMERAS;
82 read data work.cameraorientations into CAMERAS=[station];
NOTE: There were 22 observations read from the data set WORK.CAMERAORIENTATIONS.
83 set <str> ORIENTATIONS=/'NHI' 'NLO' 'EHI' 'ELO' 'SHO' 'SLO' 'WHI' 'WLO'/;
84 set <num> TARGETS;
85 num Matrix {CAMERAS, ORIENTATIONS, TARGETS};
86 read data work.CoverageMatrix into MATRIX= {c in CAMERAS, r in ORIENTATIONS, t in TARGETS}
_
22
1 NAME
____
583
87 print matrix;
_____
79
76
ERROR 22-322: Syntax error, expecting one of the following: a name, COL.
ERROR 583-782: The implied subscript count does not match array 'Matrix', 0 NE 3.
ERROR 79-322: Expecting a <.
ERROR 76-322: Syntax error, statement will be ignored.
88 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE OPTMODEL used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1035.29k
OS Memory 34228.00k
Timestamp 03/25/2021 06:25:52 PM
Step Count 58 Switch Count 0
Page Faults 0
Page Reclaims 54
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
89
90 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
102
Snippet of data from dataset work.coveragmatrix
camera orientation target k
US000A NLO 1 0
US000A NHI 1 0
US000A ELO 1 0
US000A SLO 11 1
US000A SHI 11 1
.
.
.
It looks like you forgot to read the targets, which you can do as follows:
read data targets into TARGETS=[gridpoint];
The correct READ DATA statement to populate Matrix is:
read data CoverageMatrix into [camera orientation target] Matrix=k;
It looks like you forgot to read the targets, which you can do as follows:
read data targets into TARGETS=[gridpoint];
The correct READ DATA statement to populate Matrix is:
read data CoverageMatrix into [camera orientation target] Matrix=k;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.