I have a 3 macro files that I call all 3 macro a main sas program. In one of those macro file, I need a variable that I create called "Value1". How can I access that macro variable from another 2 macro file and/or the main file.
I tried %global value1; but it can only be called within 1 macro file.
Thanks in advance.
We're guessing. We can't see your macros, we can't see the program that calls the macros, we can't see your data. So here's a guess.
It can depend on where this statement goes:
%global value1;
Place it in the program that calls the macros, before any macros get called.
Lets say we have 3 files with 1 macro in each:
sas1.sas
%global value1;
%macro sas1()
%let value1 ="apple";
%mend;
sas2.sas
%macro sas2()
%mend;
sas3.sas
%macro sas2()
%mend;
macromain.sas
%sas1;
%sas2;
%sas3;
How can I access that value1 macro from sas1 file to sas2.sas and sas3.sas? How can I access that value 1 from sas1 in macromain.sas?
Just reference it. So in your main program you could do:
%sas1;
%put Value of Value1 is &value1;
%sas2;
%sas3;
Similarly inside of %SAS2() and %SAS3().
%macro sas2;
%put Value of Value1 is &value1;
%mend sas2;
You can.
You can test that yourself, where you have:
%sas1;
%sas2;
%sas3;
Add a diagnostic statement:
%sas1;
%put &valuie1;
%sas2;
%sas3;
Most likely, you are assigning &VALUE1 the incorrect value. In your statements, you have assigned a 7-character value (quotes included) not a 5-character value.
If you're submitting your programs via batch this may not work because each program could be running in a separate session.
Assuming you're using %INCLUDE, this is how I build my 'control' programs. This allows the macro variable myVar to be available to all programs.
%let myVar = TEST; %let path_master = /folders/myfolders/projectABC *Import data; %include "&path_master/programs/P001 Import Data.sas"; *Clean data; %include "&path_master/programs/P002 Clean Data.sas"; *Generate reports %include "&path_master/programs/P003 Report Data.sas";
@Shonesum wrote:
Lets say we have 3 files with 1 macro in each:
sas1.sas
%global value1;
%macro sas1()
%let value1 ="apple";
%mend;
sas2.sas
%macro sas2()
%mend;
sas3.sas
%macro sas2()
%mend;
macromain.sas
%sas1;
%sas2;
%sas3;
How can I access that value1 macro from sas1 file to sas2.sas and sas3.sas? How can I access that value 1 from sas1 in macromain.sas?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: