For some reason this claims I have an unclosed DO loop. I am admittedly a SAS noob. I searched the board but didn't see anything that helped me answer the question (though I'm sure there must be this answer somewhere).
The data has two columns of interest- shortname (a groupingv variable) and the data in two datasets- ASet and CSet (they contain the same columns).
Before this code, there are macro variables vcshortname1, vcshortname2....vcshortname10 pre-defined.
%macro mac;
%do i=1 %to 10;
/* Separate by shortname, then run permutation test on each shortname*/
data G1;
set ASet;
if shortname = &&vcshortname.&i;
keep data;
run;
data G2;
set CSet;
if shortname = &&vcshortname.&i;
keep data;
run;
/*This should END the loop!*/
end;
/*Running code for permutation test. Got it from the community board*/
proc IML;
obsdiff = mean(G1) = mean(G2);
alldata = G1 // G2; /* stack data in a single vector */
N1 = nrow(G1); N = N1 + nrow(G2);
NRepl = 9999; /* number of permutations */
nulldist = j(NRepl,1); /* allocate vector to hold results */
do k = 1 to NRepl;
x = sample(alldata, N, "WOR"); /* permute the data */
nulldist[k] = mean(x[1:N1]) - mean(x[(N1+1):N]); /* difference of means */
end;
pval = (1 + sum(abs(nulldist) >= abs(obsdiff))) / (NRepl+1);
print pval;
title "Histogram of Null Distribution";
refline = "refline " + char(obsdiff) + " / axis=x lineattrs=(color=red);";
call Histogram(nulldist) other=refline;
quit;
%mend mac;
%mac
@abak wrote:
For some reason this claims I have an unclosed DO loop. I am admittedly a SAS noob. I searched the board but didn't see anything that helped me answer the question (though I'm sure there must be this answer somewhere).
The data has two columns of interest- shortname (a groupingv variable) and the data in two datasets- ASet and CSet (they contain the same columns).
Before this code, there are macro variables vcshortname1, vcshortname2....vcshortname10 pre-defined.
%macro mac;
%do i=1 %to 10;
/* Separate by shortname, then run permutation test on each shortname*/
data G1;
set ASet;
if shortname = &&vcshortname.&i;
keep data;
run;
data G2;
set CSet;
if shortname = &&vcshortname.&i;
keep data;
run;
/*This should END the loop!*/
%end;
/*Running code for permutation test. Got it from the community board*/
proc IML;
obsdiff = mean(G1) = mean(G2);
alldata = G1 // G2; /* stack data in a single vector */
N1 = nrow(G1); N = N1 + nrow(G2);
NRepl = 9999; /* number of permutations */
nulldist = j(NRepl,1); /* allocate vector to hold results */
do k = 1 to NRepl;
x = sample(alldata, N, "WOR"); /* permute the data */
nulldist[k] = mean(x[1:N1]) - mean(x[(N1+1):N]); /* difference of means */
end;
pval = (1 + sum(abs(nulldist) >= abs(obsdiff))) / (NRepl+1);
print pval;
title "Histogram of Null Distribution";refline = "refline " + char(obsdiff) + " / axis=x lineattrs=(color=red);";
call Histogram(nulldist) other=refline;
quit;
%mend mac;
%mac
Please see the highlighted text for how to end a %DO loop.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.