BookmarkSubscribeRSS Feed
abak
Obsidian | Level 7

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

1 REPLY 1
ballardw
Super User

@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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1095 views
  • 2 likes
  • 2 in conversation