<?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: populate vectors from a table in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90043#M565</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so very mcuh. It is a big help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Oct 2012 17:55:48 GMT</pubDate>
    <dc:creator>goliPSU</dc:creator>
    <dc:date>2012-10-09T17:55:48Z</dc:date>
    <item>
      <title>populate vectors from a table</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90041#M563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a table wchich looks like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;year&amp;nbsp;&amp;nbsp;&amp;nbsp; elec&amp;nbsp;&amp;nbsp;&amp;nbsp; ngas&amp;nbsp;&amp;nbsp;&amp;nbsp; petro&amp;nbsp;&amp;nbsp;&amp;nbsp; transp&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.328962596541413&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0333333333333333&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0294741106255071&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0312981997615055&lt;/P&gt;&lt;P&gt;1994&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.32131918710743&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0357852882703777&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0280891133921987&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0296270473156796&lt;/P&gt;&lt;P&gt;1995&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.312689346078104&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0301204819277108&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0299476941480979&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0307595385921147&lt;/P&gt;&lt;P&gt;1996&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.302492954358166&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0296846011131725&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0306720643123235&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0315941372524655&lt;/P&gt;&lt;P&gt;1997&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.297555088719812&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.037109375&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0313930047898444&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0324508531293975&lt;/P&gt;&lt;P&gt;1998&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.279078628962933&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0390455531453362&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0324409310705472&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0333306670536662&lt;/P&gt;&lt;P&gt;1999&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.269449037043657&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0390946502057613&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0338084853707251&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0342346177942214&lt;/P&gt;&lt;P&gt;2000&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.268587236213135&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0389105058365759&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0354842304721889&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0367621612481076&lt;/P&gt;&lt;P&gt;2001&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.267152131952974&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0426829268292683&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0346861443472607&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.036119401007415&lt;/P&gt;&lt;P&gt;2002&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.25010602338106&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.041501976284585&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0347417788989821&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0361976486955247&lt;/P&gt;&lt;P&gt;2003&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.249007386555198&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.04&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.034782939573557&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0362781339184914&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to automatically generate the following vectors:&lt;/P&gt;&lt;P&gt;hhd_nrg_coeff_order = {'elec', 'ngas', 'petro', 'transp'};&lt;/P&gt;&lt;P&gt;hhd_nrg_coeffs_93 = {0.328962596541413 ,&amp;nbsp;&amp;nbsp; 0.0333333333333333,&amp;nbsp;&amp;nbsp; 0.0294741106255071 ,&amp;nbsp;&amp;nbsp; 0.0312981997615055};&lt;/P&gt;&lt;P&gt;hhd_nrg_coeffs_94 = {0.32131918710743 ,&amp;nbsp;&amp;nbsp; 0.0357852882703777,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0280891133921987,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0296270473156796};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;hhd_nrg_coeffs_03 = {0.249007386555198&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.04&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.034782939573557&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0362781339184914}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is there any way to generate it automatically in SAS.&lt;/P&gt;&lt;P&gt;because I have more data till 2010 so it is gana be nasty in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 16:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90041#M563</guid>
      <dc:creator>goliPSU</dc:creator>
      <dc:date>2012-10-09T16:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: populate vectors from a table</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90042#M564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure, but I'd recommend using a matrix and nidexing the rows instead of creating separate row vectors, one for each row of the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I'd do (this code has not been run...might have syntax errors). To get the var names, use&lt;/P&gt;&lt;P&gt;use MyData;&lt;/P&gt;&lt;P&gt;read all var _NUM_ into X[colname=hhd_nrg_coeff_order];&lt;/P&gt;&lt;P&gt;close MyData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That sets the vector hhd_nrg_coeff_order to {"year"..."transp"};&lt;/P&gt;&lt;P&gt;Then extract the first column and convert it to a character vector:&lt;/P&gt;&lt;P&gt;y = X[,1];&lt;/P&gt;&lt;P&gt;year = char(y);&lt;/P&gt;&lt;P&gt;X = X[,2:ncol(X)]; /* strip off first col */&lt;/P&gt;&lt;P&gt;hhd_nrg_coeff_order = hhd_nrg_coeff_order[,2:ncol(X)];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you can use a trick that I recently blogged about where you can assign the YEAR variable to be the row index.&lt;/P&gt;&lt;P&gt;The blog is &lt;A href="http://blogs.sas.com/content/iml/2012/10/01/access-rows-or-columns-of-a-matrix-by-names/" title="http://blogs.sas.com/content/iml/2012/10/01/access-rows-or-columns-of-a-matrix-by-names/"&gt; Access rows or columns of a matrix by names - The DO Loop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like this:&lt;/P&gt;&lt;P&gt;mattrib X[rowname=year];&lt;/P&gt;&lt;P&gt;You can now refer to each row by using the name of the row. For example:&lt;/P&gt;&lt;P&gt;DataFor1997 = X['1997', ];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need a loop, you can use&lt;/P&gt;&lt;P&gt;do i = 1 to nrow(year);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; z = X[year&lt;I&gt;, ]; /* get i_th row */&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* do stuff...*/&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, you can also omit the MATTRIB statement and just index the rows by i, and use year&lt;I&gt; in case you need the value of YEAR for that observation.&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 16:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90042#M564</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2012-10-09T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: populate vectors from a table</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90043#M565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so very mcuh. It is a big help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 17:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/populate-vectors-from-a-table/m-p/90043#M565</guid>
      <dc:creator>goliPSU</dc:creator>
      <dc:date>2012-10-09T17:55:48Z</dc:date>
    </item>
  </channel>
</rss>

