<?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: leave one out cross validation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531627#M5920</link>
    <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create the base data */
data have;
input hosp_id price;
cards;
1 56
1 75
1 45
1 74
2 52
2 57
2 49
2 75
3 34
3 45
3 56
;
run;

/* extract distinct id's */
proc sort
  data=have (keep=hosp_id)
  out=exclusions
  nodupkey
;
by hosp_id;
run;

/* a macro to wrap all the analysis code in, and the split */
%macro analysis(hosp_id);

data
  train
  validate
;
set have;
if hosp_id = &amp;amp;hosp_id
then output validate;
else output train;
run;

/* training and check against validate goes here */

%mend;

/* call the macro repeatedly from the distinct id's */
data _null_;
set exclusions;
call execute('%nrstr(%analysis(' !! put(hosp_id,best.) !! '));');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run the code, you can see in the log that three different sets of train/validate data are created.&lt;/P&gt;
&lt;P&gt;Make sure that each individual call of the macro creates a separate set of result datasets, or you will only get the result of the last iteration.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Jan 2019 13:17:16 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-01-31T13:17:16Z</dc:date>
    <item>
      <title>leave one out cross validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531603#M5917</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this type of longitudinal data (I have over 130 hospitals in my data set):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hospital_id&amp;nbsp; price ...&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;56&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;75&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;45&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;74&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 52&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 57&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 49&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 75&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; 34&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; 45&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; 56&lt;/P&gt;
&lt;P&gt;.........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to do leave one out cross validation. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. split data into train (hospitals 2 and 3) and test (hospital 1).&lt;/P&gt;
&lt;P&gt;2. do analysis on train .&lt;/P&gt;
&lt;P&gt;3. when i want to split data again into train (hospitals 1 and 3) and test (hospital 2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;and so on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How automatically to do data splitting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 10:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531603#M5917</guid>
      <dc:creator>viollete</dc:creator>
      <dc:date>2019-01-31T10:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: leave one out cross validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531623#M5919</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote a blog about it just&amp;nbsp; a couple of days ago.&lt;/P&gt;
&lt;P&gt;I would use proc surveyselect .........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class noprint;
table name/out=key;
run;
data _train _test;
 set key;
 if rand('bern',0.7) then output _train;
 else output _test;
run;
proc sql;
create table train as
 select * from sashelp.class where name in (select name from _train);
 
 
create table test as
 select * from sashelp.class where name in (select name from _test);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Leave one out CV would be like something: (using KEY table above + CALL EXECUTE the following code )&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; train as
 &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; sashelp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;class&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; name &lt;SPAN class="token operator"&gt;= 'xxxxxxxx'&lt;/SPAN&gt;
 
 
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; test as
 &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; sashelp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;class&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; name &lt;SPAN class="token operator"&gt;not = 'xxxxxxxx'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 13:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531623#M5919</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-31T13:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: leave one out cross validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531627#M5920</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create the base data */
data have;
input hosp_id price;
cards;
1 56
1 75
1 45
1 74
2 52
2 57
2 49
2 75
3 34
3 45
3 56
;
run;

/* extract distinct id's */
proc sort
  data=have (keep=hosp_id)
  out=exclusions
  nodupkey
;
by hosp_id;
run;

/* a macro to wrap all the analysis code in, and the split */
%macro analysis(hosp_id);

data
  train
  validate
;
set have;
if hosp_id = &amp;amp;hosp_id
then output validate;
else output train;
run;

/* training and check against validate goes here */

%mend;

/* call the macro repeatedly from the distinct id's */
data _null_;
set exclusions;
call execute('%nrstr(%analysis(' !! put(hosp_id,best.) !! '));');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run the code, you can see in the log that three different sets of train/validate data are created.&lt;/P&gt;
&lt;P&gt;Make sure that each individual call of the macro creates a separate set of result datasets, or you will only get the result of the last iteration.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 13:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/leave-one-out-cross-validation/m-p/531627#M5920</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-31T13:17:16Z</dc:date>
    </item>
  </channel>
</rss>

