<?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: Multiplication with outputs of two procedures in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467890#M5657</link>
    <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to me that what proc score does is linear combination.&lt;/P&gt;&lt;P&gt;I'm not looking for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to multiply the output of the piece of code below (which results in a 15x4 dataset)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA eigenvectors (DROP = _TYPE_ _NAME_);
 SET Princomp_stats (WHERE= (_TYPE_="SCORE" &amp;amp; _NAME_ in 
 ('PC1','PC2','PC3', 'PC4'))); *getting eigenvectors;
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by my regression estimates coming from the piece of code below (it's currently a row vector, so I also need to transpose it).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA estimates (KEEP = PC1 PC2 PC3 PC4); *getting the betas from regression with 4PCs;
 SET Reg_out;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there an easy way of doing this?&lt;/P&gt;&lt;P&gt;Unfortunately, google is not helping much =/&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jun 2018 23:03:28 GMT</pubDate>
    <dc:creator>marianaalcos</dc:creator>
    <dc:date>2018-06-05T23:03:28Z</dc:date>
    <item>
      <title>Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467571#M5642</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and I'm having a bad time trying to figure out simple tasks, such as the one below. Any help would be very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a database with 15 variables + response to which I applied PCA.&amp;nbsp;Then, I took the 4 first PCs and applied a simple regression model to it. I'm struggling to transform the PC coefficients from the regression model (the "betas" from linear regression) into coefficients for the original variables, i.e., I need to multiply the matrix of the 4 eigenvectors (a 15x4 matrix) by the column vector (4x1) of "betas".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my attempt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*running PCA;

proc princomp data=HMW.CRIME prefix=PC plots(only)=(scree)
		out=WORK.Princomp_scores outstat=WORK.Princomp_stats;
	var M So Ed Po1 Po2 LF M_F Pop NW U1 U2 Wealth Ineq Prob Time;
	title 'Principal Componentes Analysis';
run;
title;
		
*Build linear regression model with the first 4 principal components;

proc reg data=WORK.PRINCOMP_SCORES alpha=0.05 plots(only)=(diagnostics 
		observedbypredicted) outest=estimates;
	model Crime=PC1 PC2 PC3 PC4 /;
	output out=WORK.Reg_stats p=p_;
	title 'Regression Model';
	title2 'Using 4 first PC';
	run;
quit;
title;

DATA estimates (KEEP = PC1 PC2 PC3 PC4); *getting the betas from regression with 4PCs;
 SET estimates;
RUN;

DATA eigenvectors (DROP = _TYPE_ _NAME_);
 SET Princomp_stats (WHERE= (_TYPE_="SCORE")); *getting eigenvectors;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;From the above, I was able to "isolate" the betas and the complete eigenvector matrix by creating two new datasets, but I don't know how to proceed from here.&lt;/P&gt;&lt;P&gt;I thought about merging the two datasets (estimates and eigenvectors) and then performing the multiplication, but I wonder if it can be simpler than this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In R, for instance, I'd just do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;newbetas&amp;nbsp;&amp;lt;- pca$rotation[,1:4] %*% pc_betas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UPDATE___________________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to solve this using IML as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;proc iml; * use this procedure for matrix operations;&lt;BR /&gt;/* read variables from a SAS data set into a matrix */&lt;BR /&gt;varNames = {'M','So','Ed','Po1','Po2','LF','M_F','Pop','NW',&lt;BR /&gt;'U1','U2','Wealth','Ineq','Prob','Time'};&lt;BR /&gt;use work.eigenvectors;&lt;BR /&gt;read all var _ALL_ into eigen_matrix[colname=varNames];&lt;BR /&gt;print eigen_matrix;&lt;BR /&gt;close work.eigenvectors;&lt;BR /&gt;use work.estimates;&lt;BR /&gt;read all var _ALL_ into betas;&lt;BR /&gt;print betas;&lt;BR /&gt;close work.estimates;&lt;BR /&gt;alphas = eigen_matrix` * betas`; *notice the transpose symbol `;&lt;BR /&gt;print alphas;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps someone in the future since it took me a while!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 00:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467571#M5642</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-06T00:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467692#M5651</link>
      <description>&lt;P&gt;Look at PROC SCORE, one of the examples in the documentation has exactly the code you're looking for in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212098"&gt;@marianaalcos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm new to SAS and I'm having a bad time trying to figure out simple tasks, such as the one below. Any help would be very much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a database with 15 variables + response to which I applied PCA.&amp;nbsp;Then, I took the 4 first PCs and applied a simple regression model to it. I'm struggling to transform the PC coefficients from the regression model (the "betas" from linear regression) into coefficients for the original variables, i.e., I need to multiply the matrix of the 4 eigenvectors (a 15x4 matrix) by the column vector (4x1) of "betas".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my attempt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*running PCA;

proc princomp data=HMW.CRIME prefix=PC plots(only)=(scree)
		out=WORK.Princomp_scores outstat=WORK.Princomp_stats;
	var M So Ed Po1 Po2 LF M_F Pop NW U1 U2 Wealth Ineq Prob Time;
	title 'Principal Componentes Analysis';
run;
title;
		
*Build linear regression model with the first 4 principal components;

proc reg data=WORK.PRINCOMP_SCORES alpha=0.05 plots(only)=(diagnostics 
		observedbypredicted) outest=estimates;
	model Crime=PC1 PC2 PC3 PC4 /;
	output out=WORK.Reg_stats p=p_;
	title 'Regression Model';
	title2 'Using 4 first PC';
	run;
quit;
title;

DATA estimates (KEEP = PC1 PC2 PC3 PC4); *getting the betas from regression with 4PCs;
 SET estimates;
RUN;

DATA eigenvectors (DROP = _TYPE_ _NAME_);
 SET Princomp_stats (WHERE= (_TYPE_="SCORE")); *getting eigenvectors;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From the above, I was able to "isolate" the betas and the complete eigenvector matrix by creating two new datasets, but I don't know how to proceed from here.&lt;/P&gt;
&lt;P&gt;I thought about merging the two datasets (estimates and eigenvectors) and then performing the multiplication, but I wonder if it can be simpler than this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In R, for instance, I'd just do:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newbetas&amp;nbsp;&amp;lt;- pca$rotation[,1:4] %*% pc_betas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jun 2018 14:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467692#M5651</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-05T14:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467890#M5657</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems to me that what proc score does is linear combination.&lt;/P&gt;&lt;P&gt;I'm not looking for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to multiply the output of the piece of code below (which results in a 15x4 dataset)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA eigenvectors (DROP = _TYPE_ _NAME_);
 SET Princomp_stats (WHERE= (_TYPE_="SCORE" &amp;amp; _NAME_ in 
 ('PC1','PC2','PC3', 'PC4'))); *getting eigenvectors;
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by my regression estimates coming from the piece of code below (it's currently a row vector, so I also need to transpose it).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA estimates (KEEP = PC1 PC2 PC3 PC4); *getting the betas from regression with 4PCs;
 SET Reg_out;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there an easy way of doing this?&lt;/P&gt;&lt;P&gt;Unfortunately, google is not helping much =/&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jun 2018 23:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467890#M5657</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-05T23:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467906#M5658</link>
      <description>&lt;P&gt;Matrix multiplication is a series of linear combinations. Can you upload a small excel workbook that shows a fully worked example of what you need. The next easiest approach is to use a data step and temporary array.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 00:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467906#M5658</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-06T00:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467907#M5659</link>
      <description>&lt;P&gt;Please ignore my previous response.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're trying it to back transform your regression coefficients to interpret them? I don’t think that makes sense.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you should probably be using PLS and I’m going to page&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;to chime in because this is beyond me and he’s much better at these questions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 00:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467907#M5659</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-06T00:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467910#M5660</link>
      <description>Hi Reeza,&lt;BR /&gt;&lt;BR /&gt;Yes I'm trying to transform the PC coefficients into coefficients for the original variables. I appreciate your efforts, but I was able to do it using proc IML!&lt;BR /&gt;&lt;BR /&gt;I'll post the solved and the solution above.&lt;BR /&gt;Thank you so much!</description>
      <pubDate>Wed, 06 Jun 2018 00:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467910#M5660</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-06T00:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467952#M5668</link>
      <description>&lt;P&gt;Make sure you check your final results. In my understanding the eigenvectors&amp;nbsp;are applied to the standardized variables to get the PCA scores (unless you use the COV option, which is not advisable unless all your variables&amp;nbsp;share the same scale). So I think you would need to do some rescaling to express your regression coefficients in terms of the original variables.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 03:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467952#M5668</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-06T03:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467988#M5672</link>
      <description>&lt;P&gt;Hi PG,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes,the coefficients obtained with my code are for standardized data.&lt;/P&gt;&lt;P&gt;In the sequence I had to convert back to get the coefficients in the original scale.&lt;/P&gt;&lt;P&gt;But after learning proc iml I basically just applied a code I had in R to do that and it worked just fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks anyways!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 08:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/467988#M5672</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-06T08:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with outputs of two procedures</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/469408#M5713</link>
      <description>&lt;P&gt;UPDATE___________________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to solve this using IML as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;proc iml; * use this procedure for matrix operations;&lt;BR /&gt;/* read variables from a SAS data set into a matrix */&lt;BR /&gt;varNames = {'M','So','Ed','Po1','Po2','LF','M_F','Pop','NW',&lt;BR /&gt;'U1','U2','Wealth','Ineq','Prob','Time'};&lt;BR /&gt;use work.eigenvectors;&lt;BR /&gt;read all var _ALL_ into eigen_matrix[colname=varNames];&lt;BR /&gt;print eigen_matrix;&lt;BR /&gt;close work.eigenvectors;&lt;BR /&gt;use work.estimates;&lt;BR /&gt;read all var _ALL_ into betas;&lt;BR /&gt;print betas;&lt;BR /&gt;close work.estimates;&lt;BR /&gt;alphas = eigen_matrix` * betas`; *notice the transpose symbol `;&lt;BR /&gt;print alphas;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps someone in the future since it took me a while!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 21:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Multiplication-with-outputs-of-two-procedures/m-p/469408#M5713</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-11T21:11:07Z</dc:date>
    </item>
  </channel>
</rss>

