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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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