Dears:
Some macro functions(e.g: %left() function) are not parsed in SAS Studio, but they are effective in SAS EG. And base SAS of both of them are 9.4_M6.
And I wonder if I missed any global Settings in SAS Studio env?
Please find my code in below.
proc product_status;run; data test1; i=1; run; data test2; i=2; run; data test3; i=3; run; proc sql ; create table t_test as select * from dictionary.tables where libname='WORK'; select count(*) into:num from t_test where prxmatch('/^test/io',strip(memname)); ;quit; %macro test(); data all; set test1 - test%left(&num.); run; %mend; %test;
So the %LEFT() function is found and working fine.
The other issue is that sometimes inside a macro when you use macro code to generate a single token, in this case the token TEST3, the parser can get confused and see it as two tokens. So instead of coding:
set test1 - test%left(&num.);
You can either build up the token first and then use it.
%let last =test%left(&num.);
set test1 - &last;
Or add something that lets the parser see it as one token.
set test1 - %unquote(test%left(&num.));
You can also just use a simple %LET to remove the spaces from NUM.
%let num=#
set test1-test#
But the real solution is to not put the spaces into the macro variable to begin with.
select count(*) into :num trimmed from t_test where prxmatch('/^test/io',strip(memname));
...
set test1-test&num ;
Interesting problem. Please try a shorter test of the %LEFT() function. Also check the setting for SASAUTOS and set the MAUOTCOMPLOC and MAUTOLOCDISPLAY options.
%put %sysfunc(getoption(sasautos));
options MAUTOCOMPLOC MAUTOLOCDISPLAY ;
%put "%left(%str( 3))";
Please paste the results as text and not as photographs.
Thanks for your reply.
Results as following:
SAS Studio:
So the %LEFT() function is found and working fine.
The other issue is that sometimes inside a macro when you use macro code to generate a single token, in this case the token TEST3, the parser can get confused and see it as two tokens. So instead of coding:
set test1 - test%left(&num.);
You can either build up the token first and then use it.
%let last =test%left(&num.);
set test1 - &last;
Or add something that lets the parser see it as one token.
set test1 - %unquote(test%left(&num.));
You can also just use a simple %LET to remove the spaces from NUM.
%let num=#
set test1-test#
But the real solution is to not put the spaces into the macro variable to begin with.
select count(*) into :num trimmed from t_test where prxmatch('/^test/io',strip(memname));
...
set test1-test&num ;
You can eliminate the need for the %LEFT() macro call by just not storing the leading spaces into the macro variable to begin with.
select count(*)
into :num trimmed
from t_test
where prxmatch('/^test/io',strip(memname))
;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.