DATA Step, Macro, Functions and more

Variable passed to Macro, needs single quotes.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Variable passed to Macro, needs single quotes.

I have this SAS code which is not running, because in the where clause, my variables need to have single quotes around them and '&state.' causes an error.

Any help would be greatly appreciated!!!

%macro linreg(state, var);

     data data_&state_&var;

          set final_rva_5;

          where st_cd eq '&state.' and

               variable eq '&var.';

     x = _N_;

     run;

%mend;

DATA _NULL_;

  SET linreg_state_variable_peril;

  CALL EXECUTE('%LINREG('||linreg_state||','||linreg_variable||','||linreg_peril||');');

RUN;


Accepted Solutions
Solution
‎05-14-2012 01:06 PM
Super User
Posts: 17,963

Re: Variable passed to Macro, needs single quotes.

Macro variables won't resolve inside single quotes.

Why won't double quotes work in the query?

"&state."

View solution in original post


All Replies
Solution
‎05-14-2012 01:06 PM
Super User
Posts: 17,963

Re: Variable passed to Macro, needs single quotes.

Macro variables won't resolve inside single quotes.

Why won't double quotes work in the query?

"&state."

Occasional Contributor
Posts: 9

Re: Variable passed to Macro, needs single quotes.

Works like a charm!  Thanks Reeza.

Can I ask you one more question....


What should I be using for &peril._ULT_LR_R_UC?

If I call it with linreg(total), I want the code to be model total_ULT_LR_R_UC = x.

%macro linreg(peril);

     ods output 'Fit Statistics'=fit_statistics
          'Solution'=ParameterEstimates;

          proc glm data=linreg2_data;

               model &peril._ULT_LR_R_UC = x;

               weight &peril._EARNED_UC_PREMIUM;

               run; quit;

          ods output close;

%mend;

Thanks!!!!

Super User
Posts: 17,963

Re: Variable passed to Macro, needs single quotes.

I thought that would be it.

&peril._ULT_LR_R_UC

Occasional Contributor
Posts: 9

Re: Variable passed to Macro, needs single quotes.

Thanks Reeza!!

It's working perfectly now   Smiley Happy  Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 268 views
  • 0 likes
  • 2 in conversation