<?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: Bootstrap, sampling macro &amp;amp; saving the result in a 2 dimensional array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311157#M67168</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot run PROCs inside a datastep.&lt;/P&gt;
&lt;P&gt;You can use a "data _NULL_"-step however to steer and control the generation of the code / PROCs you want (this is called: dynamic data-driven code generation using FILE - PUT). The generated program is subsequently called and submitted via a %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;I will use a macro though (alternative to "&lt;SPAN&gt;dynamic data-driven code generation")&amp;nbsp;&lt;/SPAN&gt;to produce what you want.&lt;/P&gt;
&lt;P&gt;By the way: your merge statement is weird. A merge statement should mention multiple data sets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods trace off;
options mprint nosymbolgen nomlogic nomstored;

proc datasets library=WORK NoList;
 delete Sample                / memtype=DATA; run;
 delete ParameterEstimates:   / memtype=DATA; run;
 delete ALLParameterEstimates / memtype=DATA; run; 
QUIT;

%MACRO Sample_LM;
%DO i = 1 %TO 25 %BY 1;
%LET seed=%EVAL(&amp;amp;i.*3+15963);

proc surveyselect data=sashelp.class out=work.Sample NOPRINT 
     method=urs sampsize=5 seed=&amp;amp;seed.                          
     outhits;                                      
run;

*ODS OUTPUT ParameterEstimates=work.ParameterEstimates;
PROC REG data=work.Sample outest=work.ParameterEstimates noprint;
 model&amp;amp;i. : model weight = height;
run;
QUIT;

proc append base=work.ALLParameterEstimates data=work.ParameterEstimates;
run;
QUIT;

%END; /* %DO i = 1 %TO 1000 %BY 1; */
%MEND Sample_LM;

%Sample_LM
/* All coefficients for height are in the dataset work.ALLParameterEstimates */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you prefer working with a real matrix language that supports custom functions and subroutines (modules). In that case I recommend to have a look into these 2 SAS/IML books. They contain multiple in-depth and elaborated examples on bootstrapping and sampling/simulating data.&lt;/P&gt;
&lt;P&gt;IML stands for Interactive Matrix Language. You can use this matrix language within&lt;/P&gt;
&lt;P&gt;PROC IML; /* put your IML-body here */ ; QUIT;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/publishing/authors/wicklin.html" target="_blank"&gt;https://support.sas.com/publishing/authors/wicklin.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;* Statistical Programming with SAS/IML Software – Rick Wicklin – October 29, 2010&lt;/P&gt;
&lt;P&gt;* Simulating Data with SAS® – Rick Wicklin – April 2013&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Sat, 12 Nov 2016 13:33:18 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2016-11-12T13:33:18Z</dc:date>
    <item>
      <title>Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311150#M67165</link>
      <description>&lt;P&gt;Dear all;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanna doing the linear regression (a customize macro for LM, not the one offers by proc reg) for 1000 time for sample data (with replacement) and save the coefficient&amp;nbsp;of all 1000 time in an array for the next process, this is what I wrote so far, But I can't save get the result of do loop:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Sample(data);
 proc surveyselect data= &amp;amp;data out=Sample NOPRINT 
     method=urs sampsize=5                          
     outhits;                                      
run;
%mend;


data BLM (drop = j);
   merge xy;
   array time{*} _numeric_;
   do j = 1 to 1000;
      temp = %Sample(xy);
      %LM(temp);
      time{j} = want;
   end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the %LM macro doing the LM, the "want" is the array which returns the coefficient values .&lt;BR /&gt;xy&amp;nbsp;is my original data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll appreciate it if someone tell me what is my mistake.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 11:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311150#M67165</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-12T11:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311156#M67167</link>
      <description>&lt;P&gt;I see some issues in your code:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data BLM (drop = j);
   &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;merge xy;&lt;/STRONG&gt;&lt;/FONT&gt;
   array time{*} _numeric_;
   do j = 1 to 1000;
      temp = &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%Sample&lt;/STRONG&gt;&lt;/FONT&gt;(xy);
      &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%LM&lt;/STRONG&gt;&lt;/FONT&gt;(temp);
      time{j} = want;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1) &lt;STRONG&gt;Merge&lt;/STRONG&gt; is used to join two datasets or more. &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;What did you mean by &lt;STRONG&gt;xy ? &lt;/STRONG&gt;Is this a dataset name ? where is the second one ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;2) You cant run a procedure inside a data-step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;%sample&lt;/STRONG&gt; - is macro to run a procedure;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If you like to run the procedure 1000 (or any othen number) times&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; you need enter it in a macro like:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%macro loop;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %do j=1 %to 1000;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%sample(...);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %mend loop;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %loop; &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3) Your code contains the line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&amp;nbsp;%LM&lt;/STRONG&gt;(temp);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where is macro LM defined ? is it a saved macro?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Is it coded as part of a datastep or as a separated procedure ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;4) Procedure &lt;STRONG&gt;surveyselect&lt;/STRONG&gt; wiil produce output dataset, according to your code, named &lt;STRONG&gt;SAMPLE&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I don't see that you have used this dataset name in your code;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 13:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311156#M67167</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-12T13:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311157#M67168</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot run PROCs inside a datastep.&lt;/P&gt;
&lt;P&gt;You can use a "data _NULL_"-step however to steer and control the generation of the code / PROCs you want (this is called: dynamic data-driven code generation using FILE - PUT). The generated program is subsequently called and submitted via a %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;I will use a macro though (alternative to "&lt;SPAN&gt;dynamic data-driven code generation")&amp;nbsp;&lt;/SPAN&gt;to produce what you want.&lt;/P&gt;
&lt;P&gt;By the way: your merge statement is weird. A merge statement should mention multiple data sets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods trace off;
options mprint nosymbolgen nomlogic nomstored;

proc datasets library=WORK NoList;
 delete Sample                / memtype=DATA; run;
 delete ParameterEstimates:   / memtype=DATA; run;
 delete ALLParameterEstimates / memtype=DATA; run; 
QUIT;

%MACRO Sample_LM;
%DO i = 1 %TO 25 %BY 1;
%LET seed=%EVAL(&amp;amp;i.*3+15963);

proc surveyselect data=sashelp.class out=work.Sample NOPRINT 
     method=urs sampsize=5 seed=&amp;amp;seed.                          
     outhits;                                      
run;

*ODS OUTPUT ParameterEstimates=work.ParameterEstimates;
PROC REG data=work.Sample outest=work.ParameterEstimates noprint;
 model&amp;amp;i. : model weight = height;
run;
QUIT;

proc append base=work.ALLParameterEstimates data=work.ParameterEstimates;
run;
QUIT;

%END; /* %DO i = 1 %TO 1000 %BY 1; */
%MEND Sample_LM;

%Sample_LM
/* All coefficients for height are in the dataset work.ALLParameterEstimates */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you prefer working with a real matrix language that supports custom functions and subroutines (modules). In that case I recommend to have a look into these 2 SAS/IML books. They contain multiple in-depth and elaborated examples on bootstrapping and sampling/simulating data.&lt;/P&gt;
&lt;P&gt;IML stands for Interactive Matrix Language. You can use this matrix language within&lt;/P&gt;
&lt;P&gt;PROC IML; /* put your IML-body here */ ; QUIT;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/publishing/authors/wicklin.html" target="_blank"&gt;https://support.sas.com/publishing/authors/wicklin.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;* Statistical Programming with SAS/IML Software – Rick Wicklin – October 29, 2010&lt;/P&gt;
&lt;P&gt;* Simulating Data with SAS® – Rick Wicklin – April 2013&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 13:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311157#M67168</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2016-11-12T13:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311161#M67169</link>
      <description>&lt;P&gt;The methods listed in this paper may be of interest&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/forum2007/183-2007.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2007/183-2007.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Nov 2016 13:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311161#M67169</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-12T13:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311206#M67194</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8525"&gt;@koen&lt;/a&gt;&lt;BR /&gt;your advice was really helpful, many thanks.&lt;BR /&gt;&lt;BR /&gt;I would like to know if the "data" in "proc append" will be the output of a macro how we can modify it.&lt;BR /&gt;like:&lt;BR /&gt;proc append base=work.ALLParameterEstimates data=%LM(work.ParameterEstimates);&lt;BR /&gt;run;&lt;BR /&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt;I know this is technically wrong, but is there anyway to use the macro as data input for "proc append" or maybe I have to use another proc</description>
      <pubDate>Sun, 13 Nov 2016 02:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311206#M67194</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-13T02:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311215#M67202</link>
      <description>&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Sample(data);
%do i=1 %to 100;
 proc surveyselect data= &amp;amp;data out=temp NOPRINT 
     method=urs sampsize=5                          
     outhits;                                      
run;
%LM(temp)

proc append base=want data=table_from_LM force;run;
%end;
%mend;


%sample(BLM)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Nov 2016 04:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311215#M67202</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-13T04:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311218#M67204</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108727"&gt;@Marzi﻿&lt;/a&gt;&amp;nbsp;in SAS, a macro generates code. That needs to be valid syntax. It DOES NOT return a value, though you can wrangle it, but generally that's better done via PROC FCMP.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're going to repeat a section of code multiple times, that's a good indicator that you need a macro to repeat the code. However, the datasets generated need to be managed by you. For example, one parameter in a macro can be the name of the output data set. Then that can be used in a further proc or macro if required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, unless you're dealing with 10's of millions of rows I find using the BY method much easier to navigate in the long run. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2016 04:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311218#M67204</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-13T04:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Bootstrap, sampling macro &amp; saving the result in a 2 dimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311303#M67242</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;, I got the point of my mistake from your comments. thanks</description>
      <pubDate>Mon, 14 Nov 2016 02:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bootstrap-sampling-macro-amp-saving-the-result-in-a-2/m-p/311303#M67242</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-14T02:58:40Z</dc:date>
    </item>
  </channel>
</rss>

