BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mogreenly
Calcite | Level 5

Hi,

 

I have a very basic question about macros. I am trying to write a simple macro to merge two datasets. My code looks like this

 

%macro form_merge (form);

proc sql;

create table _%form as

select a.%form,a.var1

from work.data1 as A left join work.data2 as B

run;

%mend form_merge;

 

%form_merge (X);

 

However, it is not working. For the 'create table' line, I get the warning "Apparent invocation of macro FORM not resolved", and the error "22-322: Syntax error, expecting one of the following (, '-'..."

 

When I run this as just regular code (i.e., substituting X for %form), it works fine. Can someone please tell me what I'm doing wrong?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

should be create table _&form 

 

and not create table _%form 

 

And the same in

select a.&form.,a.var1

 

and not select a.%form,a.var1

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

should be create table _&form 

 

and not create table _%form 

 

And the same in

select a.&form.,a.var1

 

and not select a.%form,a.var1

Mogreenly
Calcite | Level 5

Oh dear, that's embarrassing. Thanks! (this is the first macro I've ever written)

Reeza
Super User

@Mogreenly I wrote this last week and would appreciate any feedback if you have some time. 

It's a short tutorial on making a macro, based on the concept of working code though. 

 

 

https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

 

If it doesn't make sense at all that's worth knowing as well!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1462 views
  • 0 likes
  • 3 in conversation