BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jenim514
Pyrite | Level 9

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);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 782 views
  • 0 likes
  • 2 in conversation