DATA Step, Macro, Functions and more

can macro call be imitated in the datastep

Reply
Regular Contributor
Posts: 214

can macro call be imitated in the datastep

I have a macro program which calls screened and screenfailure and it is optional. Below in the datastep i use these for calculating. If i change in the macro call instead of screened as screening and scrn fail instead of screenfailure can i make the datastep also change. I Know it is weird but can there any step where i can do.

 

		if upcase(DSTERM) in ("SCREENING" "SCREENED") then do;
		   %if &TotIncl ne %then %do;
		      &armvar="&TotName";
		   %end;
		    descr='Patients screened';
			sort1=1;
			sort2=1;
			n=count;
			n_pct=.;
			output;
		end;

		%* Screen failure*;
	    if upcase(DSTERM) in ("SCREENING FAILURE" "SCREEN FAILURE") then do;
		   %if &TotIncl ne %then %do;
		      &armvar="&TotName";
		   %end;
		   descr='Screening failures';
		   n=count;
		   n_pct=.;
           sort1=2;
		   sort2=1;
		   output;
		end;

macro call is

%macro inc(	
        Anl = sdtm.ds,
	AnlSel = %quote(DSTERM in ("SCREENED" "SCREEN FAILURE"))
etc...
);

any help

Frequent Contributor
Posts: 112

Re: can macro call be imitated in the datastep

[ Edited ]

Sas Documentation for call Execute, it is to call macro from a datastep execution.

 

http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n1q1527d51eivsn1ob5hnz0yd1hx.htm&docset...

 

 

data xxx;
.....

call execute('%inc(Anl = '||sdtm.ds/*Data step Variable*/||', AnlSel = %quote(DSTERM in ("SCREENED" "SCREEN FAILURE"))');


.....

run;

 

Super User
Super User
Posts: 9,829

Re: can macro call be imitated in the datastep

Your post makes no sense at all.  You give a brief definition of a macro called inc which is not used anywhere in the code given.  You call macros which you have not given any description.

Second up, why do you even need all these macros and such like, your just overcomplicating things for the purpose of doing it.  If you want to do some logic for screened data and some other code for non-screen then this is an if/then scenario e.g:

...
  if upcase(dsterm) in ("SCREENING","SCREENED") then do;
    /* Code to do if true */
  end;
  else do;
    /* Code to do if false */
  end;
...

Also DSTERM is a standard variable from the DS domain, why are you needing to upper case it, and check if it is in a list, the values should already be consistent within you SDTM domain - possible even as part of a value list.

Super User
Posts: 23,998

Re: can macro call be imitated in the datastep

You're mixing macro and data step logic and with out the rest of the code or any sort of sample data or a clear question it's going to be really hard to help you. 

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