hi if I have created a macro variable using the code included, how can I indicate this variable is a macro variable in other sas program? or the only time I will recall it is to using it as &total_dev where it is now a value assigned...
what I really mean is how to indicate a variable is macro but not calling it with & where a value is assigned..
proc sql noprint select distinct count(*) into :total_dev from &Portofo._dev; quit;
A macro variable is called by using the & macro trigger. Please indicate why you would not want to do this or why it would not work in your given use case.
oh I was trying to describe it in a document and wonder if there are any good ways apart from saying it in words that it is a macro variable
You always have to make clear to the SAS interpreter that it has to call the macro preprocessor to resolve the macro variable.
There are interfaces between "normal" SAS code and the macro facility that allow dynamic creation and retrieval of macro variables, namely the CALL SYMPUT(X) subroutines and the SYMGET function:
data _null_;
set sashelp.class (obs=1);
call symputx('name',name); /* store the contents of data step/dataset variable name into macro variable name */
run;
%put &=name.;
data _null_;
name = symget('name'); /* assign the contents of macro variable name to data step variable name */
put name=;
run;
data class;
set sashelp.class;
if _n_ = 1 then call symputx('name',name);
if _n_ = 10 then name = symget('name');
run;
The latter example is just for illustration, you would usually use a retained variable for this.
And you already know the INTO keyword in SQL.
Hi,
I'm confused, in your question you say "how can I indicate this variable is a macro variable in other sas program?", but in your next post you say "I was trying to describe it in a document". So are you asking how to indicate the macro variable name is a macro in a SAS program - in which case would a comment work - or are you asking how to indicate this in some kind of text document (i.e., not a SAS program) where you don't want to use the words "macro variable" (which is exactly what it is) - in which case would "store", "storage", "memory", etc. do?
Are the people who might read what you are trying to create familiar with SAS?
I think more context is required. Perhaps show us where / how you want to use it and what you want to have changed to something else.
Kind regards,
Amir.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.