DATA Step, Macro, Functions and more

% inside string

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

% inside string

[ Edited ]

Hi,

 

I am creating a file extraction macro based on this

data &output_table. (where=(filename like &filenames.));

In the definition of my macro I have the two variables:

-output_table

-filenames

 

I call my macro in another part by defining output_table, and filenames like:

filenames = "File_52%Q&period_quarter.%.xls%"

 

where period_quarter is another macrovariable equal to 1 in my case

 

When I run it I have this warning, despite it is running well and give me good results:

WARNING: Apparent invocation of macro Q1 not resolved.

Surely because it is using the % character as a macro calling.

What I don't understand is that for the second % and third %, I don't have the warning.


Do you know what happens here?

Thanks


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 6,946

Re: % inside string

The percent at the end of the string has nothing following, so it can't be a macro call. The secoind percent is follwed immediately by a dot (invalid in SAS names), so it also can't be a macro call. But the first percent is followed by something that could be a macro name, and that causes your problem.

Restructure your statement to mask the macro triggers:

filenames = 'File_52%Q'!!"&period_quarter"!!'%.xls%';
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
2 weeks ago
Super User
Posts: 6,946

Re: % inside string

The percent at the end of the string has nothing following, so it can't be a macro call. The secoind percent is follwed immediately by a dot (invalid in SAS names), so it also can't be a macro call. But the first percent is followed by something that could be a macro name, and that causes your problem.

Restructure your statement to mask the macro triggers:

filenames = 'File_52%Q'!!"&period_quarter"!!'%.xls%';
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 22

Re: % inside string

[ Edited ]

Many thanks,

 

It worked.

Super User
Posts: 6,946

Re: % inside string

BTW one of the reasons why such special characters have no place in data file names, along with blanks.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,407

Re: % inside string

Post what you are trying to do.  Supply test data in the form of a datastep.  Its highly likely there are better methods than what you are doing here.  It looks like your using % as a wildcard for instance, you would be better off fixing it down to something more like scan(file,2,".") in ("XLS","XLSX");  Although do note you may have to handle these things differntly.  Further info is needed for more help.

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 82 views
  • 1 like
  • 3 in conversation