1
votes

my purpose is pretty simple. Just want to give some values to datasets. There are 2 steps. First, is read the values into macro variables. Second, pass the macro variables to the dataset. The codes are:

First, create macro variables.

proc sql;
select procdate, prim,side,orgnname,orgnid,OrgnStTe into :procdate, :prim, :side, :orgnname, :orgnid, :OrgnStTe from ours
where objid=783125;
quit;

This step works well. Then pass the values.

data test;
set m1;
if id=184 then DO;
objid=783125;procdate=&procdate.;prim=&prim.;side=&side.;orgnname=&orgnname.;orgnid=&orgnid.;OrgnStTe=&OrgnStTe.;
END;
run;

For this step, the error is about orgnname. Not quite sure about the error. I tried %bquote(&orgnname.) and %str(&orgnname.). Both were not working.

NOTE: Line generated by the macro variable "ORGNNAME". 1 CALVARY JOHN JAMES MEMORIAL HOSPITAL ---- 388 76 ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

1

1 Answers

2
votes

When you expand the macro variable the resulting code needs to be valid SAS syntax. In your case when you want to reference a string literal the value needs to be in quotes.

ORGNNAME = "1 CALVARY JOHN JAMES MEMORIAL HOSPITAL";

So to do that with your macro variables the syntax would look like:

ORGNNAME = "&ORGNAME";

But in reality using macro variables to transfer values that are already in data sets doesn't make sense. It requires too much work and is prone to errors or value truncation. Why not just read the data from the data set instead?

data test;
  set m1;
  if id=184 then DO;
    set ours (where=(objid=783125) keep=objid procdate prim side orgnname orgnid OrgnStTe);
  end;
run;