Hi Guys,
I am trying to create the macro variables using a macro to use it in my code further but it seems those r restricted only to that macro... Can somebody help me with this
%MACRO M1(COL,TAB,MACROVAR);
PROC SQL NOPRINT;
CREATE &COL INTO :MACROVAR FROM &TAB;
QUIT;
%MEND;
%M1(MSGID,SASHELP.ADOMSG,A1);
%PUT &A1;
This gives me error ... is there any alternative to this ????
Are these excercises? https://communities.sas.com/message/133725#133725
hi
Find below a working example.
Macro variables created within a macro have usually a LOCAL scope. However you can make macro variables global, see example below
I have also made some changes to your code sample
%MACRO M1(COL,TAB,MACROVAR);
%* make the macro var global;
%global ¯ovar;
%*
* we are reading only the first obs of the table
* the TRIMMED option will take away trailing blanks
*;
PROC SQL NOPRINT;
select
&col
into
:¯ovar TRIMMED
from
&tab(obs=1)
;
quit;
%put _local_;
%MEND;
%M1(MNEMONIC,SASHELP.ADOMSG,A1)
%PUT NOTE: *&A1*;
From your code it looks like you want to be able to access some messages from a data sets. Please have a look at the
and
functions as well
I like Bruno's sasmsg function idea a lot. Here is an example I made up. Hopefully the function is not opening-and-closing the message dataset once for each call, but I am not sure. Does anybody know for sure? Bruno?
/* load the data into a sas message dataset */
proc sql;
create table heights as
select "en_US" as locale length=5
, trimn(upcase(name)) as 'KEY'n length=60
, 1 as lineno length=5
, strip(putn(height, "best8.")) as text length=1200
from sashelp.class
order by locale, 'KEY'n, lineno desc;
create index indx on heights(locale, key);
quit;
%*-- usage example --*;
options locale="en_US";
%put Alfred:***%sysfunc(sasmsg(heights, ALFRED, noquote))***;
%put Alice :***%sysfunc(sasmsg(heights, ALICE, noquote))***;
%*-- on log
Alfred:***69***
Alice :***56.5***
--*;
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.