BookmarkSubscribeRSS Feed
Jesusismygrace
Obsidian | Level 7

Good Day,

Is there a way to add a macro name to filenames. I tried the example below and got an error message that the filename does not exist.

 

 

 

%let FileName ="cbpmy20a_detail_regulatory_my20_125591_mrr_medhmo_214372.csv";

 

filename InovMRR '/sasdata3_MI_projects_hedis_vendor/production/inovalon/data/download/ry2021/MRR/Unprocessed/&Filename.';

3 REPLIES 3
ballardw
Super User

1) Macro variables do not resolve inside single quotes.

2) The . is considered a macro processor "end of variable name". So if you want to use a macro variable before a file extension you need to use two . because the first gets used by the macro processor

 

filename InovMRR "/sasdata3_MI_projects_hedis_vendor/production/inovalon/data/download/ry2021/MRR/Unprocessed/&Filename..csv";

(or what ever extension the file might have)

if the macro variable contains the extension then the second dot is not needed. But you may need to watch closely how you make that macro variable.

Tom
Super User Tom
Super User

Same answer as this thread from earlier today.

https://communities.sas.com/t5/SAS-Programming/libname-won-t-call-the-macro-variable/m-p/751254#M236...

 

The macro processor ignores strings bounded on the outside by single quotes.  Use double quotes instead.

 

SAS doesn't care which type of quotes you use, but the macro processor does.

 

Also do not include the quotes in the value of the macro variable.

%let FileName =cbpmy20a_detail_regulatory_my20_125591_mrr_medhmo_214372.csv;
filename InovMRR "/sasdata3_MI_projects_hedis_vendor/production/inovalon/data/download/ry2021/MRR/Unprocessed/&Filename.";

If for some reason you did need to have quotes in the value of your macro variable and then use that quoted string as part of a larger quoted string the use %SYSFUNC() macro function to call the QUOTE() function to add the outside quotes and make sure the result is proper SAS syntax.  

%let FileName ="cbpmy20a_detail_regulatory_my20_125591_mrr_medhmo_214372.csv";
filename InovMRR %sysfunc(quote(/sasdata3_MI_projects_hedis_vendor/production/inovalon/data/download/ry2021/MRR/Unprocessed/&Filename.));

Note that since Unix will ignore the quotes around part of the filename the version using %sysfunc(quote()) should work whether or not the macro variable includes quotes.

Jesusismygrace
Obsidian | Level 7
Good Day! Thank you for all the help. It worked like a charm

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2080 views
  • 2 likes
  • 3 in conversation