SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ANLYNG
Pyrite | Level 9

I can not get this to work. It will not resolve the macro - why ?

 

 

%let dato=%sysfunc(putn(%eval(%sysfunc(today())-2),yymmddn8.));

%put &dato;

 

filename tmp pipe 'dir "C:\SAS\Data\data _&dato._*.zip" /b';

 

Hope you can help

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Macro variables will not resolve inside single quotes.

 

Here's a workaround, you can use the macro variable &str where your FILENAME statement was.

 

%let str=filename tmp pipe %str(%')dir "C:\SAS\Data\data _&dato._*.zip" /b%str(%');
%put &=str;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Macro variables will not resolve inside single quotes.

 

Here's a workaround, you can use the macro variable &str where your FILENAME statement was.

 

%let str=filename tmp pipe %str(%')dir "C:\SAS\Data\data _&dato._*.zip" /b%str(%');
%put &=str;
--
Paige Miller
ballardw
Super User

Macro variables inside single quotes do not resolve

 

You may want to look at this code:

%let dato=%sysfunc(putn(%eval(%sysfunc(today())-2),yymmddn8.));
%put &dato;

%put in filename: 'dir "C:\SAS\Data\data _&dato._*.zip" /b';

%put in filename double quote: "dir ""C:\SAS\Data\data _&dato._*.zip"" /b";

to see that the macro variable is not resolving.

The second version uses all double quotes and doubles the quotes around the path so that the single double quote doesn't get considered as the matching quote for the first one.

 

 

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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