DATA Step, Macro, Functions and more

SAS Macro help

Reply
New Contributor
Posts: 2

SAS Macro help

Hello Guys,

need your help in macro.

below is my code.

%let a1=1;

%let a2=2;

%let a3=3;

%let a4=4;

%let a5=5;

%let a6=;

%let a7=;

%let a8=;

%let a9=;

%let a10=;

  %macro export;

%do i = 1 %to &nod;

%let nm&i = &&nm&i;

proc sort data = db.&&nm&i out = &&nm&i;

by &subject;

run;

data db1.&&nm&i;

set &&nm&i;

by &subject;

where &subject in (&a1,&a2,&a3,&a4,&a5); ***************provide subject/patient number for output data set***********************;

run;

%end;

%mend export;

%export;

now i want the result on the base of my macroparameters means if i fillup 5 macro para then in my where condition it should took only 5 variables and if i fill up 10 then it should take 10 values.i have highlited the part.

is it possible ? kindly guide me.

Thanks,

Chirayu

Frequent Contributor
Posts: 97

Re: SAS Macro help

Posted in reply to chirayujaiswal

hi,

i am still have some questions ...

what are the values you assinged to the following ?

&nod...........?

&subject...........?

And please try without macros for single value/excution......and post here...some one would help you

Regards

ALLU

New Contributor
Posts: 2

Re: SAS Macro help

Posted in reply to allurai0412

Thanks for replaying,

i just want to know how we can use all global macros in where condition with IN operator ? Means if i use 5 macro value then no need to update where condition,my where condition should be remain same. Is it possible ?

Super User
Super User
Posts: 7,074

Re: SAS Macro help

Posted in reply to chirayujaiswal

You can reference the empty macro variables in your where condition.  For example run these simple test cases.

%let a1=14;

%let a2=;

%let subject=age ;

data want ;

  set sashelp.class ;

  where &subject in (&a1,&a2);

run;

%let a1='Alfred';

%let a2=;

%let subject=name ;

data want ;

  set sashelp.class ;

  where &subject in (&a1,&a2);

run;

Respected Advisor
Posts: 4,173

Re: SAS Macro help

Posted in reply to chirayujaiswal

I believe below sample covers what you're asking for.

%let a1=1;
%let a2=2;
%let a3=3;
%let a4=4;
%let a5=5;
%let a6=;
%let a7=;
%let a8=8;
%let a9=;
%let a10=;

proc sql noprint;
  select value into :in_values separated by ','
  from dictionary.macros
  where scope='GLOBAL' and prxmatch('/A\d+/oi',name)=1 and not missing(value)
  ;
quit;

data test;
  do i= 0 to 10;
    if i in (&in_values) then output;
  end;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 281 views
  • 1 like
  • 4 in conversation