<?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: Use %scan and tranwrd? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281902#M57206</link>
    <description>&lt;P&gt;For one vs. the rest you don't need ALLCOMP and you don't need but one call to PROC REG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
   input  x1-x4;
   datalines; 
815 545 40 8699 
110 574 22 583 
571 604 36 5889 
469 594 5 3579 
246 622 57 2478 
745 652 46 5300 
508 525 25 4919 
1322 667 33 11576 
1576 605 32 7845 
1684 661 47 10225
;;;;
   run;
proc print;
   run;

%macro models(data=x,arg=x1 x2 x3 x4);
   proc reg data=&amp;amp;data outest=est noprint;
   %local i y x;
   %let i = 1;
   %let y = %scan(&amp;amp;arg,&amp;amp;i);
   %do %while(%superq(y) ne);
      %let x = %sysfunc(transtrn(&amp;amp;arg,&amp;amp;y,%str( )));
      &amp;amp;y:model &amp;amp;y = &amp;amp;x;
      run;
      %let i = %eval(&amp;amp;i + 1);
      %let y = %scan(&amp;amp;arg,&amp;amp;i);
      %end;
   %mend;
options mprint=1;
%models;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3899i69D00257407CBF32/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Jul 2016 12:22:07 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-07-03T12:22:07Z</dc:date>
    <item>
      <title>Use %scan and tranwrd?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281878#M57196</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've a dataset with 20 variables; I'd like to have each variable as a dependent variable and the other 19 as independent variables. So in total I'd have 20 regressions. Here is a sample data of 10 cases with just 4 variables x1-x4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have; input&amp;nbsp; x1 x2 x3 x4;&lt;BR /&gt;datalines;&lt;BR /&gt;x1 x2 x3 x4 &lt;BR /&gt;815 545 40 8699 &lt;BR /&gt;110 574 22 583 &lt;BR /&gt;571 604 36 5889 &lt;BR /&gt;469 594 5 3579 &lt;BR /&gt;246 622 57 2478 &lt;BR /&gt;745 652 46 5300 &lt;BR /&gt;508 525 25 4919 &lt;BR /&gt;1322 667 33 11576 &lt;BR /&gt;1576 605 32 7845 &lt;BR /&gt;1684 661 47 10225 &lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I would do if using copying and pasting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc&amp;nbsp; reg data=have;&amp;nbsp; model x1 = x2 x3 x4; run;&lt;/P&gt;
&lt;P&gt;proc&amp;nbsp; reg data=have;&amp;nbsp; model x2 = x1 x3 x4; run;&lt;/P&gt;
&lt;P&gt;proc&amp;nbsp; reg data=have;&amp;nbsp; model x3 = x1 x2 x4; run;&lt;/P&gt;
&lt;P&gt;proc&amp;nbsp; reg data=have;&amp;nbsp; model x4 = x1 x2 x3; run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could just do this way but since I need to expand the SAS code to use ODS to output parametric estimates or to output predicted values, etc., I'd very much like to have the code efficient if possible. Someone told me to use %scan and tranwrd. I tried but I guess something was missing, so it didn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2016 04:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281878#M57196</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2016-07-03T04:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan and tranwrd?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281887#M57200</link>
      <description>&lt;P&gt;1. Create a dataset with all variable combinations. See Call AllComb&lt;/P&gt;
&lt;P&gt;2. Write a macro that a) runs regression, b) captures required data, and c) appends result into master table&lt;/P&gt;
&lt;P&gt;3. Use call execute with data set from #1 to execute #2 as required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this methodology is relatively straightforward and there are examples for each step on here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have issues, post your code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2016 06:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281887#M57200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-03T06:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan and tranwrd?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281892#M57204</link>
      <description>&lt;PRE&gt;

Give you an example:



data have; 
input  x1 x2 x3 x4;
datalines; 
815 545 40 8699 
110 574 22 583 
571 604 36 5889 
469 594 5 3579 
246 622 57 2478 
745 652 46 5300 
508 525 25 4919 
1322 667 33 11576 
1576 605 32 7845 
1684 661 47 10225
;
run;

%macro m_reg(vnames=x1 x2 x3 x4);
%do i=1 %to %sysfunc(countw(&amp;amp;vnames,%str( )));
 %let y=%scan(&amp;amp;vnames,&amp;amp;i,%str( ));
 %let x=%sysfunc(tranwrd(&amp;amp;vnames,&amp;amp;y,%str( )));
 
 proc  reg data=have;  model &amp;amp;y = &amp;amp;x; run;
 
%end;
%mend;


%m_reg


&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jul 2016 07:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281892#M57204</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-03T07:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan and tranwrd?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281902#M57206</link>
      <description>&lt;P&gt;For one vs. the rest you don't need ALLCOMP and you don't need but one call to PROC REG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
   input  x1-x4;
   datalines; 
815 545 40 8699 
110 574 22 583 
571 604 36 5889 
469 594 5 3579 
246 622 57 2478 
745 652 46 5300 
508 525 25 4919 
1322 667 33 11576 
1576 605 32 7845 
1684 661 47 10225
;;;;
   run;
proc print;
   run;

%macro models(data=x,arg=x1 x2 x3 x4);
   proc reg data=&amp;amp;data outest=est noprint;
   %local i y x;
   %let i = 1;
   %let y = %scan(&amp;amp;arg,&amp;amp;i);
   %do %while(%superq(y) ne);
      %let x = %sysfunc(transtrn(&amp;amp;arg,&amp;amp;y,%str( )));
      &amp;amp;y:model &amp;amp;y = &amp;amp;x;
      run;
      %let i = %eval(&amp;amp;i + 1);
      %let y = %scan(&amp;amp;arg,&amp;amp;i);
      %end;
   %mend;
options mprint=1;
%models;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3899i69D00257407CBF32/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2016 12:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-and-tranwrd/m-p/281902#M57206</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-07-03T12:22:07Z</dc:date>
    </item>
  </channel>
</rss>

