<?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: 10-FOLD CROSS VALIDATION &amp;amp; BOOTSTRAPPING in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448485#M112822</link>
    <description>&lt;P&gt;Here is the code I wrote before for&amp;nbsp;&lt;SPAN&gt;10-FOLD CROSS VALIDATION Logistic Regression.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****** K-Fold CV ****/

%macro k_fold_cv(k=10);
ods select none;

proc surveyselect data=sashelp.heart group=&amp;amp;k out=have;
run;

%do i=1 %to &amp;amp;k ;
data training;
 set have(where=(groupid ne &amp;amp;i)) ;
run;
data test;
 set have(where=(groupid eq &amp;amp;i));
run;

ods output 
Association=native(keep=label2 nvalue2 rename=(nvalue2=native) where=(label2='c'))
ScoreFitStat=true(keep=dataset freq auc rename=(auc=true));
proc logistic data=training
 outest=est(keep=_status_ _name_) ;
 class sex;
 model status(event='Alive')=sex height weight;
 score data=test fitstat; 
run;

data score&amp;amp;i;
 merge true native est;
 retain id &amp;amp;i ;
 optimism=native-true;
run;
%end;
data k_fold_cv;
 set score1-score&amp;amp;k;
run;

ods select all;
%mend;

%k_fold_cv(k=10)








/*************************************/


%macro k_fold_cv_rep(r=1,k=10);
ods select none;
%do r=1 %to &amp;amp;r;
proc surveyselect data=sashelp.heart group=&amp;amp;k out=have;
run;

%do i=1 %to &amp;amp;k ;
data training;
 set have(where=(groupid ne &amp;amp;i)) ;
run;
data test;
 set have(where=(groupid eq &amp;amp;i));
run;

ods output 
Association=native(keep=label2 nvalue2 rename=(nvalue2=native) where=(label2='c'))
ScoreFitStat=true(keep=dataset freq auc rename=(auc=true));
proc logistic data=training
 outest=est(keep=_status_ _name_) ;
 class sex;
 model status(event='Alive')=sex height weight;
 score data=test fitstat; 
run;

data score_r&amp;amp;r._&amp;amp;i;
 merge true native est;
 retain rep &amp;amp;r id &amp;amp;i;
 optimism=native-true;
run;
%end;
%end;
data k_fold_cv_rep;
 set score_r:;
run;

ods select all;
%mend;

%k_fold_cv_rep(r=20,k=10);

/********************/
data all;
 set k_fold_cv k_fold_cv_rep indsname=indsn;
 length indsname $ 32;
 indsname=indsn;
run;
proc summary data=all nway;
 class indsname;
 var optimism;
 output out=want mean=mean lclm=lclm uclm=uclm;
run;




&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 25 Mar 2018 08:39:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-03-25T08:39:29Z</dc:date>
    <item>
      <title>10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448436#M112799</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to combine 10-fold cross-validation and Bootstrapping in the same macro. But i have the impression that I am missing the Bootstrapping&amp;nbsp; loop. I was wondering if you would be able to advise me what is wrong on my code below please?&amp;nbsp; Is there a better way to combine&amp;nbsp;&lt;SPAN&gt;10-fold cross-validation and Bootstrapping&amp;nbsp;in the same macro?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data kyphosis;
 * infile cards dlm='09'x;
  input y1	y2 d;
  cards;
13	100	0
64	437	0
12	334	0
618	285	0
104	150	0
65	136	0
1573	523	0
291	927	0
84	62	0
13	54	0
338	248	1
758	917	1
189	305	1
260	88	1
223	257	1
604	231	1
366	1106	1
1094	658	1
176	65	1
1499	147	1
69	319	1
,
run;

%macro bootstrap (bootnum); *bootnum=12;

 *******************************************************************************
BOOTSTRAPPING
*******************************************************************************;

proc surveyselect data=kyphosis NOPRINT seed=1234
     out=kyphosis1(rename=(Replicate=bootsample))
     method=urs              
     samprate=100  
     outhits            
     reps=&amp;amp;bootnum;       
run;

*******************************************************************************
10-FOLD CROSS VALIDATION
*******************************************************************************;

 data kyphosis1;
     set kyphosis1;
      theRandom = ranuni(0);
	  *by bootsample;
    run;

proc rank data = kyphosis1 out=kRanked groups=10;
*by bootsample;
	var theRandom;
run;

%do x = 0 %to 9;


******************************************************************************
Create Training Data 
*******************************************************************************;
data training&amp;amp;x;
set kRanked;
where theRandom ne &amp;amp;x;
*by bootsample;
run;

******************************************************************************
Generate Binary variable beta1 for Biomarker 1 
*******************************************************************************;

proc sql;
create table temp&amp;amp;x as
select 
    a.y1 as compare_y1,
    b.*,
    a.y1 &amp;lt; b.y1 as beta
from training&amp;amp;x as a, training&amp;amp;x as b;
*order by compare_y1, y1;
quit;

******************************************************************************
Generate Binary variable beta1 for Biomarker 2
*******************************************************************************;

proc sql;
create table temp2&amp;amp;x as
select 
    a.y2 as compare_y2,
    b.*,
    a.y2 &amp;lt; b.y2 as beta1
from training&amp;amp;x as a, training&amp;amp;x as b;
*order by compare_y2, y2;
quit;


******************************************************************************
Merge Temp and Temp2 
*******************************************************************************;

data want&amp;amp;x;
merge temp&amp;amp;x temp2&amp;amp;x;
run;

******************************************************************************
Generate Combined Binary variable beta1_beta2 and Append 
*******************************************************************************;

data final&amp;amp;x;
set want&amp;amp;x;
if beta=1 &amp;amp; beta1=1 then beta1_beta2=1;
if beta=1 &amp;amp; beta1=0 then beta1_beta2=1;
if beta=0 &amp;amp; beta1=1 then beta1_beta2=1;
if beta=0 &amp;amp; beta1=0 then beta1_beta2=0;
run;

******************************************************************************
Calculate se, spec, ect...
*******************************************************************************;

proc sort data=final&amp;amp;x;
         by  compare_y1 compare_y2;
         run;

		 
proc freq data = final&amp;amp;x order=data noprint ;
by compare_y1 compare_y2;
            tables  beta1_beta2*d / out=freq_results&amp;amp;x OUTPCT sparse ;
			*output out=mnocol;
run;

******************************************************************************
Create Test Data 
*******************************************************************************;

data test&amp;amp;x; * The test dataset, called test0 (when x=0), test1 (when x=1), etc.;
set kRanked;
where theRandom = &amp;amp;x;
run;

******************************************************************************
 APPEND THE RESULTS OF THE SELECTED CUTOFFS IN THE TRAING SET 
*******************************************************************************;
proc append base = Base force data = freq_results&amp;amp;x; 
run;

%end; *end 10-FOLD CROSS VALIDATION loop;
%mend;
%bootstrap(12);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Mar 2018 16:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448436#M112799</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-24T16:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448443#M112803</link>
      <description>&lt;P&gt;Why not do a 2-fold, generate a log, and see what is missing from the log, if anything (using OPTIONS MPRINT; prior to invoking the macro)?&amp;nbsp; If you find something missing, show us what you expected in the log, vs what you got.&amp;nbsp; It'll be a long log, so you might want to mask out the parts remote from any apparent problem area.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if the resulting data is different than what you expect, then again provide what you expected vs what you got.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Diagnosis benefits from observation of results, as well as inference from the program logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 18:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448443#M112803</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-24T18:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448446#M112806</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;has written some good posts on this subject&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/tag/bootstrap-and-resampling" target="_blank"&gt;https://blogs.sas.com/content/iml/tag/bootstrap-and-resampling&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 18:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448446#M112806</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-24T18:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448463#M112812</link>
      <description>&lt;P&gt;I was missing bootstrapping loop below.The program is working now. Thanks for letting me think:)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;bootnum;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end; *end Boostraping;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 22:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448463#M112812</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-24T22:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448464#M112813</link>
      <description>Many thanks</description>
      <pubDate>Sat, 24 Mar 2018 22:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448464#M112813</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-24T22:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448485#M112822</link>
      <description>&lt;P&gt;Here is the code I wrote before for&amp;nbsp;&lt;SPAN&gt;10-FOLD CROSS VALIDATION Logistic Regression.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****** K-Fold CV ****/

%macro k_fold_cv(k=10);
ods select none;

proc surveyselect data=sashelp.heart group=&amp;amp;k out=have;
run;

%do i=1 %to &amp;amp;k ;
data training;
 set have(where=(groupid ne &amp;amp;i)) ;
run;
data test;
 set have(where=(groupid eq &amp;amp;i));
run;

ods output 
Association=native(keep=label2 nvalue2 rename=(nvalue2=native) where=(label2='c'))
ScoreFitStat=true(keep=dataset freq auc rename=(auc=true));
proc logistic data=training
 outest=est(keep=_status_ _name_) ;
 class sex;
 model status(event='Alive')=sex height weight;
 score data=test fitstat; 
run;

data score&amp;amp;i;
 merge true native est;
 retain id &amp;amp;i ;
 optimism=native-true;
run;
%end;
data k_fold_cv;
 set score1-score&amp;amp;k;
run;

ods select all;
%mend;

%k_fold_cv(k=10)








/*************************************/


%macro k_fold_cv_rep(r=1,k=10);
ods select none;
%do r=1 %to &amp;amp;r;
proc surveyselect data=sashelp.heart group=&amp;amp;k out=have;
run;

%do i=1 %to &amp;amp;k ;
data training;
 set have(where=(groupid ne &amp;amp;i)) ;
run;
data test;
 set have(where=(groupid eq &amp;amp;i));
run;

ods output 
Association=native(keep=label2 nvalue2 rename=(nvalue2=native) where=(label2='c'))
ScoreFitStat=true(keep=dataset freq auc rename=(auc=true));
proc logistic data=training
 outest=est(keep=_status_ _name_) ;
 class sex;
 model status(event='Alive')=sex height weight;
 score data=test fitstat; 
run;

data score_r&amp;amp;r._&amp;amp;i;
 merge true native est;
 retain rep &amp;amp;r id &amp;amp;i;
 optimism=native-true;
run;
%end;
%end;
data k_fold_cv_rep;
 set score_r:;
run;

ods select all;
%mend;

%k_fold_cv_rep(r=20,k=10);

/********************/
data all;
 set k_fold_cv k_fold_cv_rep indsname=indsn;
 length indsname $ 32;
 indsname=indsn;
run;
proc summary data=all nway;
 class indsname;
 var optimism;
 output out=want mean=mean lclm=lclm uclm=uclm;
run;




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Mar 2018 08:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448485#M112822</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-25T08:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448494#M112826</link>
      <description>Many thanks Ksharp. I am exploring it now</description>
      <pubDate>Sun, 25 Mar 2018 13:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448494#M112826</guid>
      <dc:creator>jeka1212</dc:creator>
      <dc:date>2018-03-25T13:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: 10-FOLD CROSS VALIDATION &amp; BOOTSTRAPPING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448499#M112827</link>
      <description>&lt;P&gt;In the case of large datasets, where efficiency&amp;nbsp; becomes an issue,&amp;nbsp; instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data training;
 set have(where=(groupid ne &amp;amp;i)) ;
run;
data test;
 set have(where=(groupid eq &amp;amp;i));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;consider using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data training test / view=training;
  set have;
  if groupid=&amp;amp;i then output test;
  else output training;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It creates both data sets simultaneously, so there's one pass through HAVE. &amp;nbsp; In addition, since training is a view (while test is a file), the data are not processed until training is submitted to proc logistic.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Mar 2018 15:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/448499#M112827</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-25T15:09:12Z</dc:date>
    </item>
  </channel>
</rss>

