BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello,

Could anyone let me know why my Do loop code didn't work?  Thanks.

%let Y1=sum;
%let Y2=los;
%let X1=age;
%let X2=Preterm;
%let X3=ICU;

%macro aaa;


proc npar1way WILCOXON data=Pre_Cal;

%do z  = 1 %to 2;
%do i  = 1 %to 3;

	class &&X&i..;
	var &&Y&z..;

	%end; 
	%end; ;

run;

%mend;
%aaa;
10 REPLIES 10
Astounding
PROC Star

You have extra dots in the CLASS and VAR statements.  Get rid of them (at least get rid of one per statement).

 

No, on second thought that's not it.  

 

Have you considered posting the log?

ybz12003
Rhodochrosite | Level 12
I got rid of one dot in both Class and Var statements, but it is still not working.
ybz12003
Rhodochrosite | Level 12

I run the codes, then nothing happed.  Log window message was shown.

 

Spoiler
345 options mprint symbolgen mlogic;
346 %let Y1=sum;
347 %let Y2=los;
348 %let X1=age;
349 %let X2=Preterm;
350 %let X3=ICU;

353
354
355 %macro aaa;
356
357
358 proc npar1way WILCOXON data=Pre_Cal;
359
360 %do z = 1 %to 2;
361 %do i = 1 %to 3;
362
363 class &&X&i..;
364 var &&Y&z..;
365
366 %end;
367 %end; ;
368
369 run;
370
371 %mend;
372 %aaa;
Astounding
PROC Star

That's really it???  No further messages after that in the log???

ybz12003
Rhodochrosite | Level 12
yes, that is.
Astounding
PROC Star

Them something else must have gone wrong in the earlier code ... a missing semicolon, a missing %mend statement, ... something that isn't presented here.  I would suggest starting a new SAS session and re-running the code.

Tom
Super User Tom
Super User

What SAS code is it that you are trying to generate?

I do not use that PROC but the syntax you are trying to generate looks really fishy to me.

What would this code even mean?

proc npar1way WILCOXON data=Pre_Cal;
class age;
var sum;

class preterm;
var sum;

class ICU;
var sum;

class age;
var los;

class preterm;
var los;

class ICU;
var los;

run;

Normally you just have one VAR statement and one CLASS statement in a proc.  You could use multiple class statements if for some reason you needed to use differing options for some of the class variables.

Reeza
Super User

@Tom is correct, your loop is in the wrong location

 

See code below for the fix and example that works.

%let Y1=sum;
%let Y2=los;
%let X1=age;
%let X2=Preterm;
%let X3=ICU;

%macro aaa;

%do z  = 1 %to 2;
%do i  = 1 %to 3;
proc npar1way WILCOXON data=Pre_Cal;



	class &&X&i..;
	var &&Y&z..;



run;
	%end; 
	%end; ;
%mend;

options mprint symbolgen;
%aaa;
%let Y1=ageatstart;
%let Y2=height;
%let X1=weight_status;
%let X2=deathcause;
%let X3=smoking_status;

%macro aaa;

%do z  = 1 %to 2;
%do i  = 1 %to 3;
proc npar1way WILCOXON data=sashelp.heart;



	class &&X&i..;
	var &&Y&z..;



run;
	%end; 
	%end; ;
%mend;

options mprint symbolgen;
%aaa;
Tom
Super User Tom
Super User

Looks like you only need to the %DO loop over the CLASS variables.  You can only have one CLASS variable but you can have many variables on the VAR statement.

You also only need TWO macro variables. One to list the CLASS variables and one to list the analysis variables.

Making a "series" of macro variables is just adding extra work for no real advantage.

 

%let classes=age preterm icu;
%let varlist=sum los;
%do i=1 to %sysfunc(countw(&classes,%str( )));
proc npar1way WILCOXON data=Pre_Cal;
  class %scan(&classes,&i,%str( ));
  var &varlist;
run;
%end;
ballardw
Super User

You might indicate what code you are attempting to generate.

 

Looks like a very cumbersome approach without more details. 

 

One suspects that you have created an unstable situation with one or more attempts to execute the code and it is time to restart SAS if the Log isn't actually showing the MPRINT output.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 10 replies
  • 679 views
  • 5 likes
  • 5 in conversation