<?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: Vector Space Model in SAS in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Vector-Space-Model-in-SAS/m-p/309139#M3071</link>
    <description>&lt;P&gt;You didn't provide what your data look like, so I'll just have to guess. Try the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In the DATA step, use the COUNTW and SCAN&amp;nbsp;functions to parse the keys, so that the data has one key in each row&lt;/LI&gt;
&lt;LI&gt;In SAS/IML use the UNIQUE and UNIQUEBY functions to find the rows that start each field. For details, see&lt;BR /&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/11/07/an-efficient-alternative-to-the-unique-loc-technique.html" target="_self"&gt;"An efficient alternative to the UNIQUE-LOC technique."&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Use the ELEMENT function to find the location of the keys for each row. Fopr details, see&amp;nbsp;&lt;BR /&gt;&lt;A href="http://blogs.sas.com/content/iml/2014/03/17/finding-elements-in-one-vector-that-are-not-in-another-vector.html" target="_self"&gt;"Finding elements in one vector that are not in another vector"&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length s $100;
input s &amp;amp; $;   /* special character '&amp;amp;' reads until 2 or more blanks */
Field = _N_;
cnt = countw(s, ' ');
do i = 1 to cnt;
   key = scan(s, i, ' ');
   output;
end;
datalines;
112 1454 122 342
122 1343 32
;

proc iml;
use Have;
read all var {"Field" "Key"};
close;

Fields = unique(Field);
Keys = unique(Key);
Result = j(ncol(Fields), ncol(Keys), 0);

/* http://blogs.sas.com/content/iml/2011/11/07/an-efficient-alternative-to-the-unique-loc-technique.html */
b = uniqueby(Field, 1);   /* b[i] = beginning of i_th category */
b = b // (nrow(Field)+1); /* trick: append (n+1) to end of b */
do i = 1 to nrow(b)-1;    /* For each level... */
   idx = b[i]:(b[i+1]-1); /*   Find observations in level */
   /* http://blogs.sas.com/content/iml/2014/03/17/finding-elements-in-one-vector-that-are-not-in-another-vector.html */
   Result[i,] = element(Keys, Key[idx]);
end;

F = char(Fields);
print Result[rowname=F colname=Keys];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Nov 2016 20:05:29 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-11-03T20:05:29Z</dc:date>
    <item>
      <title>Vector Space Model in SAS</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Vector-Space-Model-in-SAS/m-p/309101#M3070</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an observation with two text fields that contain&amp;nbsp;listings of error keys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to convert these fields into two vectors the have a zero/one indicator for each error&amp;nbsp;key. I then need to be able to perform some basic matrix algebra on the vectors and store the results (a numeric value) in a third picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EXAMPLE&lt;/P&gt;
&lt;P&gt;Field 1: “112 1454 122 342”&lt;/P&gt;
&lt;P&gt;Field 2: “122 1343 32”&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key for Vector Element&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 112 1454 122 342 1343 32&lt;/P&gt;
&lt;P&gt;Field 1 Vector:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;Field 2 Vector:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is essentially a numerical application of the Salton Wong and Yang (1975) vector space model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have any code handy to do this, or can anyone point me to resources where I can learn it myself? I've been struggling to find stuff.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you all!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 17:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Vector-Space-Model-in-SAS/m-p/309101#M3070</guid>
      <dc:creator>mbaugh</dc:creator>
      <dc:date>2016-11-03T17:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Vector Space Model in SAS</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Vector-Space-Model-in-SAS/m-p/309139#M3071</link>
      <description>&lt;P&gt;You didn't provide what your data look like, so I'll just have to guess. Try the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In the DATA step, use the COUNTW and SCAN&amp;nbsp;functions to parse the keys, so that the data has one key in each row&lt;/LI&gt;
&lt;LI&gt;In SAS/IML use the UNIQUE and UNIQUEBY functions to find the rows that start each field. For details, see&lt;BR /&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/11/07/an-efficient-alternative-to-the-unique-loc-technique.html" target="_self"&gt;"An efficient alternative to the UNIQUE-LOC technique."&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Use the ELEMENT function to find the location of the keys for each row. Fopr details, see&amp;nbsp;&lt;BR /&gt;&lt;A href="http://blogs.sas.com/content/iml/2014/03/17/finding-elements-in-one-vector-that-are-not-in-another-vector.html" target="_self"&gt;"Finding elements in one vector that are not in another vector"&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length s $100;
input s &amp;amp; $;   /* special character '&amp;amp;' reads until 2 or more blanks */
Field = _N_;
cnt = countw(s, ' ');
do i = 1 to cnt;
   key = scan(s, i, ' ');
   output;
end;
datalines;
112 1454 122 342
122 1343 32
;

proc iml;
use Have;
read all var {"Field" "Key"};
close;

Fields = unique(Field);
Keys = unique(Key);
Result = j(ncol(Fields), ncol(Keys), 0);

/* http://blogs.sas.com/content/iml/2011/11/07/an-efficient-alternative-to-the-unique-loc-technique.html */
b = uniqueby(Field, 1);   /* b[i] = beginning of i_th category */
b = b // (nrow(Field)+1); /* trick: append (n+1) to end of b */
do i = 1 to nrow(b)-1;    /* For each level... */
   idx = b[i]:(b[i+1]-1); /*   Find observations in level */
   /* http://blogs.sas.com/content/iml/2014/03/17/finding-elements-in-one-vector-that-are-not-in-another-vector.html */
   Result[i,] = element(Keys, Key[idx]);
end;

F = char(Fields);
print Result[rowname=F colname=Keys];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2016 20:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Vector-Space-Model-in-SAS/m-p/309139#M3071</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-11-03T20:05:29Z</dc:date>
    </item>
  </channel>
</rss>

