<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to complete an incomplete binary matrix? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974276#M377863</link>
    <description>Brilliant! Thank you so much!&lt;BR /&gt;Gene</description>
    <pubDate>Fri, 05 Sep 2025 17:09:35 GMT</pubDate>
    <dc:creator>genemroz</dc:creator>
    <dc:date>2025-09-05T17:09:35Z</dc:date>
    <item>
      <title>How to complete an incomplete binary matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974257#M377853</link>
      <description>&lt;P&gt;Esteemed Advisers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’ve been away from SAS coding for a while so I’m probably overlooking a relatively simple solution.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Here’s the problem (greatly simplified to aid understanding):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A Camera Network has three Cameras.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Camera C1&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;can take one of two different Orientations (O1,O2) to cover, respectively, two targets (T1,T2). The other two cameras (C2,C3) can also take on two orientations (O1, O2).&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Because they have different optical properties, C2 can cover only T1 with&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;O1 and C3 can cover only T2&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;with orientation O2.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the coverage matrix (k) for C1 looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; O1 &amp;nbsp; &amp;nbsp; O2&lt;/P&gt;
&lt;P&gt;T1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;T2 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For C2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; O1 &amp;nbsp; &amp;nbsp; O2&lt;/P&gt;
&lt;P&gt;T1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;T2 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For C3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; O1 &amp;nbsp; &amp;nbsp; O2&lt;/P&gt;
&lt;P&gt;T1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;T2 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My HAVE dataset (see code below) produces the correct coverage matrix for C1. However, for C2 and C3&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;the dataset only contains observations where an orientation covers a target and none for orientations that do not cover targets.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;My WANT dataset must contain all possibilities of coverage (k=1) or non-coverage (k=0) for all cameras and all target/orientation combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the attached code for exemplar Have/Want code and a failed attempt to use Update.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at these simple coverage matrices suggests to me that perhaps some kind of array processing might be called for but I’m not proficient in that area of SAS. &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My real-life application consists of &amp;nbsp;several cameras, hundreds/thousands of targets and 24 possible orientations.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;The resulting binary matrix is needed for input to Proc Optmodel for optimizing camera orientation.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I’d like to find a dynamic solution that doesn’t require operator intervention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any help you can provide,&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input C $ O $ T $ k;
cards;
C1 O1 T1 1
C1 O1 T2 1
C1 O2 T1 1
C1 O2 T2 1
C2 O1 T1 1
C3 O2 T2 1
run;
proc sort data=Have;
Title "Have";
by T C O;
run;

Proc freq data=Have;
Title "Have";
tables C*O;
run;

data Want;
input C $ O $ T $ k;
cards;
C1 O1 T1 1
C1 O1 T2 1
C1 O2 T1 1
C1 O2 T2 1
C2 O1 T1 1
C2 O1 T2 0
C2 O2 T1 0
C2 O2 T2 0
C3 O1 T1 0
C3 O1 T2 0
C3 O2 T1 0
C3 O2 T2 1
;

proc sort data=want;
by T C O;
run;

Proc freq data=want;
Title "Want";
tables C*O;
run;

Proc sort data=want;
by C;
run;

Proc freq data=want;
by C;
Title "Want";
tables T*O;
run;

/* Failed attempt to create Want (for only C2) using Update */
data Master;
set Have;
where C ='C2';
run;

Proc sort data=Master;
by T O;
run;

Data Transaction;
set Have (rename=(k=k0));
by T C;
where C='C1';
run;

Proc sort data=Transaction;
by  T O;
run;

Data WantbyUPDATE;
update Master Transaction;
by T O;
if missing(k) then kk=0; else kk=k;
run;

proc sort data=WantbyUPDATE;
by C O;

Proc freq data=WantbyUPDATE;
Title "WantbyUPDATE";
tables C*O;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Sep 2025 14:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974257#M377853</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2025-09-05T14:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to complete an incomplete binary matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974261#M377856</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299716"&gt;@genemroz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try PROC FREQ with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_freq_syntax08.htm#procstat.freq.freqsparse" target="_blank" rel="noopener"&gt;SPARSE option&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint;
tables T*C*O / sparse out=want(rename=(count=k) drop=percent);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or PROC SUMMARY with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1qnc9bddfvhzqn105kqitnf29cp.htm#n10z5tfgi3j0h9n19pq7bbgn9tve" target="_blank" rel="noopener"&gt;NWAY&lt;/A&gt; and &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1qnc9bddfvhzqn105kqitnf29cp.htm#n1terqe3hgwedcn1fvzn3i20lh6o" target="_blank" rel="noopener"&gt;COMPLETETYPES&lt;/A&gt; options&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway completetypes;
class T C O;
output out=want(rename=(_freq_=k) drop=_type_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Sep 2025 15:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974261#M377856</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-09-05T15:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to complete an incomplete binary matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974276#M377863</link>
      <description>Brilliant! Thank you so much!&lt;BR /&gt;Gene</description>
      <pubDate>Fri, 05 Sep 2025 17:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-complete-an-incomplete-binary-matrix/m-p/974276#M377863</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2025-09-05T17:09:35Z</dc:date>
    </item>
  </channel>
</rss>

