DATA Step, Macro, Functions and more

global or local output variable?

Reply
Regular Contributor
Regular Contributor
Posts: 170

global or local output variable?

Hello all;

I have a macro that runs just fine. It is just that I want to call a piece of it somewhere else outside the macro without adding an additional data step. Code below followed by question:


%macro split (data=, var=, var1=, var2=);
proc sort data=&data(keep=&var &var1 &var2) out=values nodupkey;
by &var;
run;
data _null_;
set values end=last;
call symputx('M'||left(_n_),&var);
if last then call symput('count',_n_);
run;
%put _local_;
.....rest of macro

%mend split;
%split(data=HISTORY.ACUTEEXP, var=VISIT, Var1=start ,var2=end);



My question concerns the line:
if last then call symput('count',_n_);

I should be be able to call the "count" after the macro runs into anoter part of program?
If I try to call it, it remains unresolved.

Any solutions, greatly appreciated.

~Lawrence
Valued Guide
Posts: 2,177

Re: global or local output variable?

force the value into the global environment by replacing symput() with symputx(), like:

if last then call symputX('count',_n_, 'g' );
Regular Contributor
Regular Contributor
Posts: 170

Re: global or local output variable?

Peter;
Worked like a charm!
Much Thanks!

Lawrence
Super Contributor
Super Contributor
Posts: 3,174

Re: global or local output variable?

Also, here's a very useful and pertinent SAS support website http://support.sas.com/ DOC supplement tech note reference, found using the site's SEARCH facility:

Special Cases of Scope with the CALL SYMPUT Routine - SAS v9 DOC:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/tw3514-symput.htm


Examples of Macro Variable Scopes - SAS v8 but still applies today:
http://v8doc.sas.com/sashtml/macro/z1072111.htm
Ask a Question
Discussion stats
  • 3 replies
  • 120 views
  • 0 likes
  • 3 in conversation