Something like this?
/* 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 = &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;
When you run the code, you can see in the log that three different sets of train/validate data are created.
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.
... View more