Help using Base SAS procedures

macro variables in location

Accepted Solution Solved
Reply
Super Contributor
Posts: 259
Accepted Solution

macro variables in location


I have a filename defined in my dataset:

 

filename cm  'k:\may 2015\cm.txt';

and in another program the month and year are defined as:

%let month = may;

%let year = 2015;

when I used the code

filename cm  'k:\&month. &year.\cm.txt';

it doesn't work


Accepted Solutions
Solution
‎07-23-2015 02:38 PM
PROC Star
Posts: 1,167

Re: macro variables in location

1. As previously mentioned, use double quotes not single.

2. Is your SAS session possibly running on a server that can't see your K: drive?

3. Could the macro variables be local when they're created, not global? In the program that's failing, put in the line

%put &month &year;

to see if the variables have values.

View solution in original post


All Replies
Valued Guide
Posts: 860

Re: macro variables in location

What does the log say?

Super User
Posts: 19,770

Re: macro variables in location

Macro variables need double quotes to resolve, they won't resolve in single quotes

Super Contributor
Posts: 259

Re: macro variables in location

Log says...

Physical file does not exist,

'k:\&month. &year.\cm.txt'

it doesn't work with double quotations either.

Super User
Posts: 19,770

Re: macro variables in location

Use the following line to see what the macro variables are resolving to, also, make sure that the file actually exists Smiley Happy

Options symbolgen mprint;

If that doesn't work, post your full code and log.

Solution
‎07-23-2015 02:38 PM
PROC Star
Posts: 1,167

Re: macro variables in location

1. As previously mentioned, use double quotes not single.

2. Is your SAS session possibly running on a server that can't see your K: drive?

3. Could the macro variables be local when they're created, not global? In the program that's failing, put in the line

%put &month &year;

to see if the variables have values.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 317 views
  • 0 likes
  • 4 in conversation