<?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 put the dot product of two vector macro variables into data step equations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419418#M280447</link>
    <description>&lt;P&gt;If &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24314"&gt;@jint83&lt;/a&gt;&amp;nbsp;is correct and this is coming from proc glmselect then help us out by running the model and then posting the result of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put _user_;&lt;/PRE&gt;
&lt;P&gt;This will give us the actual names and contents of the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or try adding a line something like this to your code (before the run statement)&lt;/P&gt;
&lt;PRE&gt;   ods output parameterestimates= work.parms;&lt;/PRE&gt;
&lt;P&gt;Which will create a data set with the effect and the parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't mention if by groups are involved but for a single model&lt;/P&gt;
&lt;PRE&gt;data _null_;
   set work.parms end=eof;
   length longstr $ 500;
   retain longstr;
   longstr = catx(' + ',longstr, catx('*',effect,estimate));
   call symputx('Formula',longstr);
run;

%put &amp;amp;formula;&lt;/PRE&gt;
&lt;P&gt;appears to do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2017 00:18:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-12-08T00:18:30Z</dc:date>
    <item>
      <title>How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419051#M280442</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="effects10.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17053i28F37D0498F4F690/image-size/large?v=v2&amp;amp;px=999" role="button" title="effects10.png" alt="effects10.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="coeffs.png" style="width: 642px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17054iC8A70BBE39D22201/image-dimensions/642x61?v=v2" width="642" height="61" role="button" title="coeffs.png" alt="coeffs.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;effects and &amp;amp;estimate are regression results stored in vector macro variables.&lt;/P&gt;&lt;P&gt;As shown in the pictures above, &amp;amp;effects is the vector variable with the names of effects.&lt;/P&gt;&lt;P&gt;&amp;amp;estimate are the vector of coefficients.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;say &amp;amp;effects is "a b c d e f g".&lt;/P&gt;&lt;P&gt;&amp;amp;estimate is "1 2 3 4 5 6 7"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I use these two macro variables to create a data step equation that equals to the dot product of the two vectors?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code that I tried, but it did not produce the correct result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;effects));&lt;BR /&gt;%let effects&amp;amp;i = %scan(&amp;amp;effects, &amp;amp;i, %str( ));&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;estimate));&lt;BR /&gt;%let estimate&amp;amp;i = %scan(&amp;amp;estimate, &amp;amp;i, %str( ));&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%let total1=&amp;amp;effects1*estimate1;&lt;BR /&gt;%let largeN=%sysfunc(countw(&amp;amp;effects));&lt;/P&gt;&lt;P&gt;%do i=2 %to %sysfunc(countw(&amp;amp;effects));&lt;BR /&gt;%let total&amp;amp;i = total%eval(&amp;amp;i-1).+&amp;amp;effects&amp;amp;i*&amp;amp;estimate&amp;amp;i;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%put &amp;amp;total&amp;amp;largeN; &amp;nbsp; &amp;nbsp; &amp;nbsp;[&amp;lt;-this should be the yhat definition, it is an expression like a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data option2;&lt;BR /&gt;set opion1;&lt;BR /&gt;yhat=&amp;amp;total&amp;amp;largeN; &amp;nbsp; [&amp;lt;-this equation should be the same as "yhat=&lt;SPAN&gt;a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7"]&lt;/SPAN&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me to solve this problem? Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2017 03:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419051#M280442</guid>
      <dc:creator>YutongHu</dc:creator>
      <dc:date>2017-12-07T03:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419060#M280443</link>
      <description>&lt;P&gt;Well, you could cut out a few pieces in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data option2;&lt;/P&gt;
&lt;P&gt;set option1;&lt;/P&gt;
&lt;P&gt;yhat =&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;effects));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%scan(&amp;amp;effects, &amp;amp;i) * %scan(&amp;amp;estimate, &amp;amp;i)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%if &amp;amp;i &amp;lt; %sysfunc(countw(&amp;amp;effects)) %then + ;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does have to be inside a macro definition, to permit %if and %do.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2017 03:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419060#M280443</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-07T03:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419072#M280444</link>
      <description>&lt;P&gt;I would say, don’t create this problem in the first place.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are multiple ways to score new data, this doesn’t seem like a good approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that’s what you’re doing of course.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2017 04:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419072#M280444</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-07T04:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419230#M280445</link>
      <description>&lt;P&gt;Please explain what the overall purpose of the generated data step code.&lt;/P&gt;
&lt;P&gt;If your macro variable lists came from a data set it may be that using that data set and some data transformation in a data step&amp;nbsp;will work in a much cleaner manner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are going to use multiple identical calls such as&lt;/P&gt;
&lt;P&gt;%sysfunc(countw(&amp;amp;effects))&lt;/P&gt;
&lt;P&gt;perhaps you would be better off calling that once and assigning the value to another macro variable. Then you could make the code a little cleaner:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %do I = 1 to &amp;amp;EffectCount;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2017 16:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419230#M280445</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-07T16:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419286#M280446</link>
      <description>&lt;P&gt;Speaking on behalf of the poster. These macros, did not come from a dataset, so the question cannot be avoided,&amp;nbsp;as the macros definitions come from SAS GLM select outputs:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_glmselect_sect022.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_glmselect_sect022.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know the answer to poster's question, but I do think the question is an important one that&amp;nbsp;begs to be addressed within the framework of the poster's question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2017 18:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419286#M280446</guid>
      <dc:creator>jint83</dc:creator>
      <dc:date>2017-12-07T18:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419418#M280447</link>
      <description>&lt;P&gt;If &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24314"&gt;@jint83&lt;/a&gt;&amp;nbsp;is correct and this is coming from proc glmselect then help us out by running the model and then posting the result of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put _user_;&lt;/PRE&gt;
&lt;P&gt;This will give us the actual names and contents of the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or try adding a line something like this to your code (before the run statement)&lt;/P&gt;
&lt;PRE&gt;   ods output parameterestimates= work.parms;&lt;/PRE&gt;
&lt;P&gt;Which will create a data set with the effect and the parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't mention if by groups are involved but for a single model&lt;/P&gt;
&lt;PRE&gt;data _null_;
   set work.parms end=eof;
   length longstr $ 500;
   retain longstr;
   longstr = catx(' + ',longstr, catx('*',effect,estimate));
   call symputx('Formula',longstr);
run;

%put &amp;amp;formula;&lt;/PRE&gt;
&lt;P&gt;appears to do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 00:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419418#M280447</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-08T00:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419460#M280448</link>
      <description>&lt;P&gt;I tried the code, but it still did not work. Thank you anyway.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 03:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419460#M280448</guid>
      <dc:creator>YutongHu</dc:creator>
      <dc:date>2017-12-08T03:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419462#M280449</link>
      <description>&lt;P&gt;The problem was that I predicted the model using&amp;nbsp;sample A, but I also want to use the model to test the accuracy of the model on sample B. However, I only know the step that directly produces predicted yhat for&amp;nbsp;sample A. That is why I need to create a formula by macro variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 03:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419462#M280449</guid>
      <dc:creator>YutongHu</dc:creator>
      <dc:date>2017-12-08T03:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419463#M280450</link>
      <description>&lt;P&gt;Hi, the problem was that I predicted the model from sample A.&lt;/P&gt;&lt;P&gt;Let's say the model is &amp;nbsp;yhat=a + b*1 + c*2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate yhat not only for the observations in sample A, but also for the observations in sample B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simpler way that I can use to avoid using macro variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 03:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419463#M280450</guid>
      <dc:creator>YutongHu</dc:creator>
      <dc:date>2017-12-08T03:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the dot product of two vector macro variables into data step equations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419464#M280451</link>
      <description>&lt;P&gt;See the various methods here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 03:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-dot-product-of-two-vector-macro-variables-into/m-p/419464#M280451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-08T03:39:18Z</dc:date>
    </item>
  </channel>
</rss>

