BookmarkSubscribeRSS Feed
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
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
3 REPLIES 3
Peter_C
Rhodochrosite | Level 12
force the value into the global environment by replacing symput() with symputx(), like:

if last then call symputX('count',_n_, 'g' );
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Peter;
Worked like a charm!
Much Thanks!

Lawrence
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1062 views
  • 0 likes
  • 3 in conversation