BookmarkSubscribeRSS Feed
Aspa
Calcite | Level 5
Hi All,

I have 30 different datasets in SAS and I would like to merge each one of them with a standard one I have. I am trying to write a macro to do that automatically for me. Unfortunately my macro (see below) does not work and I am not sure why this is the case. I get an error message:

WARNING: Apparent symbolic reference DISEASE_CLINIC not resolved.
ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.


%macro merge(disease=);
proc sql;
create table test.&disease_clinic as
select *
from test.clinical_diagnosis left join test.&disease
on clinical_diagnosis.medcode=&disease.medcode;
quit;
%mend merge;
%merge (disease=tia);

Any ideas would be greatly appreciated.

Thanks,
A
2 REPLIES 2
ballardw
Super User
I think the problem is in the line:

create table test.&disease_clinic as

SAS is expecting a macro variable named Disease_clinic to have been defined.
If you are wanting to use the name of the variable concatenated with _clinic the syntax should be:
create table test.&disease._clinic as

SAS uses a period to indicate the end of the macro variable name when used in compounds such as this.
DF
Fluorite | Level 6 DF
Fluorite | Level 6
You'll have the same issues in your column references too. E.g.:

clinical_diagnosis.medcode=&disease.medcode;

If the macro variable &disease computes to "ALPHA" then this would be equivalent to:

clinical_diagnosis.medcode=ALPHAmedcode;

If you're using the macro variable to reference a table name, then simply add a second dot, so

clinical_diagnosis.medcode=&disease..medcode;

Would become

clinical_diagnosis.medcode=ALPHA.medcode;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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