SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

vname to the rescue

Started ‎03-27-2019 by
Modified ‎07-18-2019 by
Views 1,884

I'm writing a user-written transformation for a whole series of DI jobs. I can't get all the metadata I need from the macro variables created for source table, so I did what I normally do: read dictionary.columns. And it worked fine - until one of the tables came from SQL Server with a non-standard name: TEST_TABLE$. This is represented as "TEST_TABLE$"n, and when I pass that into my query, it gets resolved as ""TEST_TABLE$"n", which won't work...

 

What to do? What to do? Hmm - how about this?

 

%let _target_name = "TEST_TABLE$"n;

data _null_;
retain &_target_name ' '; /* Prevent warning message */
call symput('meta_target_name', strip(vname(&_target_name))); /* vname strips the trailing 'n' and quotes */
run;

%put &=meta_target_name;

 

And it returns:

META_TARGET_NAME=TEST_TABLE$

 

I've only ever used vname and its friends for walking over an array of columns, and never for a single column. But in this case it did exactly what I wanted, and I was able to pass "&meta_target_name" directly into my query. So much easier than much more complicated ways of stripping of the trailing n and dequoting (or unquoting; I can never remember) the result.

 

I think I deserve a beer. As does the inventor of vname.

 

See also

Version history
Last update:
‎07-18-2019 08:19 AM
Updated by:

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags