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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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