<?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: computing the sensitivity for each variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309508#M66610</link>
    <description>&lt;PRE&gt;

DATA x;
      input x1 x2 x3 x4; 
    datalines ; 
    1 2 3 5
    3 4 4 6
    5 6 9 7
	8 5 6 7
   ; 
run;

DATA b;
      input b1 b2 b3 b4; 
    datalines ; 
    0.3 0.4 0.5 0.1
   ; 
run;
%let dsid=%sysfunc(open(x));
%let nvar=%sysfunc(attrn(&amp;amp;dsid,nvars));
%let dsid=%sysfunc(close(&amp;amp;dsid));
proc summary data = x;
var x: ;
output out=mean (drop=_:) mean= ;
run;
data want;
 merge b mean;
 array b{*} b:;
 array x{*} x:;
 array s{*} sens1-sens&amp;amp;nvar;
 do i=1 to &amp;amp;nvar;
  sum+b{i}*x{i};
 end;
 
 do i=1 to &amp;amp;nvar;
  do j=1 to &amp;amp;nvar;
   if j=i then temp+b{j}*x{j}*2;
    else temp+b{j}*x{j};
  end; 
  s{i}=temp/sum;
 end;
drop i j temp sum;
run;
 

&lt;/PRE&gt;</description>
    <pubDate>Sat, 05 Nov 2016 14:05:56 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-05T14:05:56Z</dc:date>
    <item>
      <title>computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309335#M66509</link>
      <description>&lt;P&gt;I would like to compute the sensitivity base on the following formula for each variable, however, I have difficulty to use proc inside a MACRO. the other problem is about the number of variables which are not fixed always.&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5657i4AD044F731D1BDAA/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to write my code,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_loop (data=, coef=);
data &amp;amp;data;
 set &amp;amp;data;
 set &amp;amp;coef;
 array cp {*)_numeric_;
array nvar {*} _numeric_;
%do  i = 1 to dim(nvar);
  Sens_&amp;amp;i. = 1+ (cp_&amp;amp;i *mean(nvar_&amp;amp;i))/(mult(cp , nvar));
%end;
run;
%mend do_loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;this code definitely returns the error.&lt;BR /&gt;but I would very appreciate it if you help me how I can improve my code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 15:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309335#M66509</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-04T15:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309364#M66525</link>
      <description>&lt;P&gt;If your %do i loop is supposed to address array members then do not use %do. The %do is not going to have any idea what the value of the dim of an array is. Macros generate code that is compiled and not much on the way of examining data step variable values at execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of Sens_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i create another array to hold the results.&lt;/P&gt;
&lt;P&gt;Array references are:&amp;nbsp;&amp;nbsp; arrayname {index} where the index can be inside parantheses, braces or [ ]&lt;/P&gt;
&lt;P&gt;So CP [i]&lt;/P&gt;
&lt;P&gt;However datastep handles one row of data at a time and you are apparently attempting a MATRIX operation which means you either need to go to Proc IML&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the future it really helps us if you post Log results with error messages. If running macros&amp;nbsp;use OPTIONS MPRINT SYMBOLGEN; run the code and post the log complete with error messages in the code box that opens when clicking on the "run" icon in the message menu list to preserve layout.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 17:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309364#M66525</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-04T17:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309491#M66597</link>
      <description>&lt;PRE&gt;
Yeah. It is better for IML. Post is at IML forum.
and where is your data? and can you explain these symbols in formula .
b hat, x bar  stand for what ?

&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Nov 2016 10:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309491#M66597</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-05T10:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309494#M66600</link>
      <description>&lt;P&gt;Do you have the parameter estimates &amp;nbsp;(b hats) and the sample means (x bars) &amp;nbsp;already stored in a data set, or is that part of the problem? In otherwords, are we starting with the raw variables or with the estimates? &amp;nbsp;Also, does your formula assume anything about the variables, such as they are centered (have mean zero)?&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2016 10:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309494#M66600</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-11-05T10:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309499#M66603</link>
      <description>&lt;P&gt;I have some restriction, only I can use SAS Base.&lt;/P&gt;&lt;P&gt;Bs are estimated coefficient &amp;amp; x_bar&amp;nbsp;is the sample mean.&lt;BR /&gt;BTW, we have these value, don't need to compute them again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2016 11:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309499#M66603</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-05T11:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309500#M66604</link>
      <description>I have estimated B and sample mean (x bar).&lt;BR /&gt;Yes, the data are centered, means we can assume that b0 is equal to zero.</description>
      <pubDate>Sat, 05 Nov 2016 11:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309500#M66604</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-05T11:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309504#M66606</link>
      <description>&lt;P&gt;this is what I write so far, but the final result is NULL&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA x;
      input x1 x2 x3 x4; 
    datalines ; 
    1 2 3 5
    3 4 4 6
    5 6 9 7
	8 5 6 7
   ; 
run;

DATA b;
      input b1 b2 b3 b4; 
    datalines ; 
    0.3 0.4 0.5 0.1
   ; 
run;


%macro trans (Beta , n);
proc fcmp;
   array bb [1,&amp;amp;n] / nosymbols;
   array tb [&amp;amp;n,1];
   rc = read_array('@Beta', bb);
   call transpose(bb, tb);
   put tb =;
   rc = write_array('tb', tb);
quit;
%mend;

%macro multi (datax, Beta,n);
%trans(&amp;amp;Beta, &amp;amp;n);
proc summary data = &amp;amp;datax nway;
var x: ;
output out=mean (drop=_:) mean= ;
run;
proc fcmp;
   array xm [1,&amp;amp;n]/ nosymbols;
   array c [&amp;amp;n, 1]/ nosymbols;
   array result[1,1];
  
   rc = read_array('tb', c);
   rc = read_array('work.mean',xm );
   call mult (xm, c,result);
   put result=;
   rc = write_array('bx', result);
 quit;
%mend;

%multi(x,b,4);

Data Sens;
set work.mean;
array y[*]_numeric_;
set  work.TB;
array D[*]_numeric_;
array Sens[*]_numeric_;
set work.BX;
array BetaX[*]_numeric_;

do i = 1 to dim(Sens);
Sens[i] = 1 + y[i]*D[i]/BetaX[1];
end;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Nov 2016 12:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309504#M66606</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-05T12:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309508#M66610</link>
      <description>&lt;PRE&gt;

DATA x;
      input x1 x2 x3 x4; 
    datalines ; 
    1 2 3 5
    3 4 4 6
    5 6 9 7
	8 5 6 7
   ; 
run;

DATA b;
      input b1 b2 b3 b4; 
    datalines ; 
    0.3 0.4 0.5 0.1
   ; 
run;
%let dsid=%sysfunc(open(x));
%let nvar=%sysfunc(attrn(&amp;amp;dsid,nvars));
%let dsid=%sysfunc(close(&amp;amp;dsid));
proc summary data = x;
var x: ;
output out=mean (drop=_:) mean= ;
run;
data want;
 merge b mean;
 array b{*} b:;
 array x{*} x:;
 array s{*} sens1-sens&amp;amp;nvar;
 do i=1 to &amp;amp;nvar;
  sum+b{i}*x{i};
 end;
 
 do i=1 to &amp;amp;nvar;
  do j=1 to &amp;amp;nvar;
   if j=i then temp+b{j}*x{j}*2;
    else temp+b{j}*x{j};
  end; 
  s{i}=temp/sum;
 end;
drop i j temp sum;
run;
 

&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Nov 2016 14:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309508#M66610</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-05T14:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309509#M66611</link>
      <description>&lt;PRE&gt;

DATA x;
      input x1 x2 x3 x4; 
    datalines ; 
    1 2 3 5
    3 4 4 6
    5 6 9 7
	8 5 6 7
   ; 
run;

DATA b;
      input b1 b2 b3 b4; 
    datalines ; 
    0.3 0.4 0.5 0.1
   ; 
run;
%let dsid=%sysfunc(open(x));
%let nvar=%sysfunc(attrn(&amp;amp;dsid,nvars));
%let dsid=%sysfunc(close(&amp;amp;dsid));
proc summary data = x;
var x: ;
output out=mean (drop=_:) mean= ;
run;
data want;
 merge b mean;
 array b{*} b:;
 array x{*} x:;
 array s{*} sens1-sens&amp;amp;nvar;
 do i=1 to &amp;amp;nvar;
  sum+b{i}*x{i};
 end;
 
 do i=1 to &amp;amp;nvar;
  temp=0;
  do j=1 to &amp;amp;nvar;
   if j=i then temp+b{j}*x{j}*2;
    else temp+b{j}*x{j};
  end; 
  s{i}=temp/sum;
 end;
drop i j temp sum;
run;
 

&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Nov 2016 14:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309509#M66611</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-05T14:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309511#M66612</link>
      <description>Use the second one, the first one is not right.</description>
      <pubDate>Sat, 05 Nov 2016 14:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309511#M66612</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-05T14:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: computing the sensitivity for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309555#M66632</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;</description>
      <pubDate>Sun, 06 Nov 2016 01:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/computing-the-sensitivity-for-each-variable/m-p/309555#M66632</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-06T01:30:44Z</dc:date>
    </item>
  </channel>
</rss>

