Help using Base SAS procedures

ABC of macro

Reply
Occasional Contributor
Posts: 12

ABC of macro

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;
Respected Advisor
Posts: 3,890

Re: ABC of macro

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;
Occasional Contributor
Posts: 12

Re: ABC of macro

Perfect, thank you very much.
It works fine.
Take care
Respected Advisor
Posts: 3,890

Re: ABC of macro

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
Occasional Contributor
Posts: 12

Re: ABC of macro

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
Ask a Question
Discussion stats
  • 4 replies
  • 159 views
  • 0 likes
  • 2 in conversation