BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HB
Barite | Level 11 HB
Barite | Level 11

I am working inside a macro.  Everything is running nicely and I am proud of myself for making this thing.  Going to save me some time. I have one little thing.

 

I do an SQL statement and I select some stuff along with 

'&myvariable._myfilename only' as location like 

proc sql;
	title 'differences';
	select foo, '&myvariable._myfilename only' as location
	from bar 
etc

The &myvariable. won't resolve to the value inside the quoted SQL.

If when I ran the macro myvariable were ABC, I would want location to have the value 'ABC_myfilename only' in the output. 

 

I've tried CATS and 'stuff'n and some other silly stuff.

I'm guessing it's a little piece of syntax I don't know and can't find.  

   

Can you help?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Congrats, you should be proud of yourself!  The macro language is hard.

 

The little bit of syntax you're missing is the fact that macro variables don't resolve inside of single quotes.  If you change to double quotes, it should work fine.

 

proc sql;
	title 'differences';
	select foo, "&myvariable._myfilename only" as location
	from bar 
etc
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

4 REPLIES 4
Quentin
Super User

Congrats, you should be proud of yourself!  The macro language is hard.

 

The little bit of syntax you're missing is the fact that macro variables don't resolve inside of single quotes.  If you change to double quotes, it should work fine.

 

proc sql;
	title 'differences';
	select foo, "&myvariable._myfilename only" as location
	from bar 
etc
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
HB
Barite | Level 11 HB
Barite | Level 11
Really SAS? Really? You're going to do that to me? Single vs double quotes. LOL.

Thanks a ton, works a treat.
Tom
Super User Tom
Super User

@HB wrote:
Really SAS? Really? You're going to do that to me? Single vs double quotes. LOL.

Thanks a ton, works a treat.

Think it through.  How else so you make a string that actually has the value &X ?  By having the macro processor ignore strings in single quotes it is easy to prevent the macro process from messing up strings that just happen to look like macro code.  

HB
Barite | Level 11 HB
Barite | Level 11
In many languages/programs, either double and single quotes can be used interchangeably, so as a solution double quotes didn't jump off the screen at me. I appreciated the response that actually solved my problem.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 624 views
  • 2 likes
  • 3 in conversation