Single quotes in macros

Reply
Occasional Contributor
Posts: 8

Single quotes in macros

I want to run a set of code for several different years. I have put my code into a macro with parameter year. However, I must use year a both a numeric variable and a character variable within my program. Is there a was of getting around having to include year as two parameters - one numeric and one in single quotes?

This is a simplification of the problem. In reality I hoping to significantly reduce the number of paprameters in my macro.

%macro doyear(year, yearstr);

data test;

     set file&year;

     if group=&yearstr;

run;

%doyear(year=2013, yearstr='2013');

Any suggestions would be appreciated!

Sarasvati

Respected Advisor
Posts: 3,776

Re: Single quotes in macros

%macro doyear(year);

data test;

     set file&year;

     if group="&year";

run;

%doyear(year=2013);

Trusted Advisor
Posts: 1,203

Re: Single quotes in macros

You can pass one parameter and use it for both numeric and character variables.

%macro doyear(year);

data test;

     set file&year;

     if group="&year"

run;

%mend doyear;

%doyear(year=2013);

Occasional Contributor
Posts: 8

Re: Single quotes in macros

Thank you so much! Such a simple solution!

Ask a Question
Discussion stats
  • 3 replies
  • 149 views
  • 3 likes
  • 3 in conversation