BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NickZhengCHN
Calcite | Level 5

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;

sas_eg.pngsas_studio.png

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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 ;

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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.

NickZhengCHN
Calcite | Level 5

Thanks for your reply.

 

Results as following:

SAS  Studio:

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73
74 %put %sysfunc(getoption(sasautos));
( "SASEnvironment/SASMacro" '!SASROOT/sasautos' )
75 options MAUTOCOMPLOC MAUTOLOCDISPLAY ;
76 %put "%left(%str( 3))";
MAUTOCOMPLOC: The autocall macro LEFT is compiling using the autocall source file
/opt/sasinside/SASHome/SASFoundation/9.4/sasautos/left.sas.
MAUTOLOCDISPLAY(LEFT): This macro was compiled from the autocall file /opt/sasinside/SASHome/SASFoundation/9.4/sasautos/left.sas
MAUTOCOMPLOC: The autocall macro VERIFY is compiling using the autocall source file
/opt/sasinside/SASHome/SASFoundation/9.4/sasautos/verify.sas.
MAUTOLOCDISPLAY(VERIFY): This macro was compiled from the autocall file
/opt/sasinside/SASHome/SASFoundation/9.4/sasautos/verify.sas
"3"
77
78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 
SAS EG:
 
34 %put %sysfunc(getoption(sasautos));
SASAUTOS
35 options MAUTOCOMPLOC MAUTOLOCDISPLAY ;
36 %put "%left(%str( 3))";
MAUTOCOMPLOC: The autocall macro LEFT is compiling using the autocall source file
D:\SAS94\SASHome\SASFoundation\9.4\core\sasmacro\left.sas.
MAUTOLOCDISPLAY(LEFT): This macro was compiled from the autocall file D:\SAS94\SASHome\SASFoundation\9.4\core\sasmacro\left.sas
MAUTOCOMPLOC: The autocall macro VERIFY is compiling using the autocall source file
D:\SAS94\SASHome\SASFoundation\9.4\core\sasmacro\verify.sas.
MAUTOLOCDISPLAY(VERIFY): This macro was compiled from the autocall file D:\SAS94\SASHome\SASFoundation\9.4\core\sasmacro\verify.sas
"3"
Tom
Super User Tom
Super User

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 ;

 

Tom
Super User Tom
Super User

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))
;

SAS Innovate 2025: Register Now

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!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 842 views
  • 2 likes
  • 2 in conversation