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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1586 views
  • 0 likes
  • 3 in conversation