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?
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
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
Oh dear, that's embarrassing. Thanks! (this is the first macro I've ever written)
@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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.