BookmarkSubscribeRSS Feed
Hani
Calcite | Level 5
Hello all,

I would like to run the following two programs with a macro. Can somebody help me.

I need to run it for different cases (from 1 to 10), and what I need to vary from 1 to 10 are specified below.

I have basic knowledge in macros, and I appreciate your help.

Thanks


data sample1; /*sample1 to sample10*/
set sample;
if id_case=1; /*case1 to case10*/
run;

data Control;
merge Control1 /*control1 to control10*/
Sample1 ; /*sample1 to sample10*/
by ID_case;
run;
4 REPLIES 4
Patrick
Opal | Level 21
Not tested:

%macro MergeCtrlSmpl;
%do case=1 %to 10;
data CTRL_&case;
merge Control&case
Sample&case (where=(id_case=&case)) ;
by ID_case;
run;

proc append base=control data=CTRL_&case force;
run;
%end;
%mend;

%MergeCtrlSmpl;
Hani
Calcite | Level 5
Perfect, thank you very much.
It works fine.
Take care
Patrick
Opal | Level 21
Hi Hani

Below code for SAS9.2 would allow you to get your desired result without the use of macro code at all (which I believe is always preferable):


data control;
merge sample(where=(id_case GE 1 and id_case LE 10))
control1 - control10;
by id_case;
run;


HTH
Patrick Message was edited by: Patrick
Hani
Calcite | Level 5
Hello Patrick,

Thanks for the suggestion, I will run it as well. I prefer not to use macros as I am not very comfortable with it.. I hope this will work as well.

Thanks
hani

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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