DATA Step, Macro, Functions and more

macro to create a shell for multiple treatment groups

Accepted Solution Solved
Reply
Regular Contributor
Posts: 180
Accepted Solution

macro to create a shell for multiple treatment groups

Hi all,  I need a little help with a macro.  I basically need the below code to repeat exactly for the 9 treatment groups to create a dummy shell.  I then the output from each treatment group to 'stack' as to create a large shell  with 31 observations output from each treatment group.  The away this is currently written, I am only getting output from group 'T" (the last entered group).

 

Help is appreciated!

 

 

%macro dummy (tx);
data dummy ;
do tx="&tx";
	do ord=11 to 41;
		if ord=11 then do;
		do sord=1 to 2 ;
		output;
		end;
		end;
	if ord=21 then do;
		do sord=1 to 8;
		output;
		end;
		end;

	if ord=31 then do;
		do sord=1 to 12;
		output;
		end;
		end;
	if ord=41 then do;
		do sord=1 to 9;
		output;
		end;
		end;
	end;
end;
run;
%mend dummy;
%dummy (A);
%dummy (B);
%dummy (C);
%dummy (D);
%dummy (E);
%dummy (F);
%dummy (G);
%dummy (H);
%dummy(T);

 

 


Accepted Solutions
Solution
‎03-19-2018 03:33 PM
Super User
Posts: 6,543

Re: macro to create a shell for multiple treatment groups

To get your program to work, get rid of the macro language.  Take this statement:

 

do tx="&tx";

 

Change it to:

 

do tx = 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'T';

 

Then you can get rid of everything that is macro-related and be left with a DATA step.

 

As it stands now, each time you call the macro, you replace the data set DUMMY.  That seems like the wrong thing to do.

View solution in original post


All Replies
Solution
‎03-19-2018 03:33 PM
Super User
Posts: 6,543

Re: macro to create a shell for multiple treatment groups

To get your program to work, get rid of the macro language.  Take this statement:

 

do tx="&tx";

 

Change it to:

 

do tx = 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'T';

 

Then you can get rid of everything that is macro-related and be left with a DATA step.

 

As it stands now, each time you call the macro, you replace the data set DUMMY.  That seems like the wrong thing to do.

Regular Contributor
Posts: 180

Re: macro to create a shell for multiple treatment groups

Posted in reply to Astounding
Thank you @Astounding!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 103 views
  • 0 likes
  • 2 in conversation