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
BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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
BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 418 views
  • 2 likes
  • 3 in conversation