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!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.