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

Very curious.  I'd sworn there were no trailing blanks in the macro value and I was wrong.

Earlier in the code I created the macro variable with this code figuring it would remove trailing blanks.  The maximum length of tableName is 30 characters and the length of _uniqTable1 was 30 when the trailing blanks are counted.

     %** Get the unique table names.   ;

     select unique strip(tableName) label='Unique Table Name'

     into : _uniqDbTable1

     %if &_nUniqTables > 1 %then -

          : _uniqDbTable&_nUniqTables ;

     from  &project_name._cell_ltr_tables;

So why does %let _table= &&_uniqDbTable&_n remove trailing blanks but the Proc SQL syntax didn't?

If this is a feature of Proc SQL then I'm going to have to be more careful going forward because I use it a lot to create macro variables.

Thanks to all who contributed.

John

Tom
Super User Tom
Super User

%LET removes the spaces because spaces are interpreted as token delimiters.  So %let X=     xxxx        ; is the same as %let X=xxxx;

You do not need that macro logic.  You can let PROC SQL take care of knowing how many macro variables to make. If you have a newer version of SAS then just do not put anything after the hyphen.  If you have an older version then just use some obviously too large value for the upper bound.  SAS will only create the number of macro variables that it needs.  It will also count the number of values for you.

%** Get the unique table names.   ;

select unique tableName

  into :_uniqDbTable1 - :_uniqDbTable9999

  from &project_name._cell_ltr_tables

;

%let _nUniqTables = &sqlobs ;

jakarman
Barite | Level 11

John there is a difference in macro language parsing and sas language parsing.  Gergely Bathó already mentioned that.
With the datastep and proc sql you can put literally every kind of character into a macro variable

SAS(R) 9.4 SQL Procedure User's Guide (using macro vars) the trim is explicitly activated with concatenating the content. As it mentioned is not by default.

for the datastep there is new function SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition (symputx) is trims space and let you control wich symboltable you are using. Be carefull on that one too as local tables can or may not be nested.

The macro quoting (SAS(R) 9.4 Macro Language: Reference, Second Edition - SAS(R) 9.4 Macro Language: Reference, Second Edition (%quote an %unquote) are to be used when you are defining character in a macro-variable that can conflict with the macro-language. Very predictable and constant in behavior.

As rule of thumb: when possible conflicting chars can occur use %nrquote at the moment of defining and %unquote when using.

---->-- ja karman --<-----

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

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
  • 17 replies
  • 4442 views
  • 6 likes
  • 6 in conversation