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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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