Michael Ancel
Michael Ancel

Reputation: 95

SAS type issue using a macro function

I have a macro function defined as below.

%macro sqlloop(event_id, empl_nbr_var, fleet, base, position);
...lots of code...
%mend;

the actual code will be referencing based on a bigger table, but for troubleshooting and simplicity I have a shortened version of just the first row of this table, row1.

event_id empl_nbr_var fleet base position
1234 111 320 CHS A

checking this in output data all of the types of Character except event_id, which is numeric. This is exactly what I want for the program. when I manually type in this, it works perfectly.

%sqlloop(1234, '111', '320', 'CHS', 'A');

however the following code throws all kinds of errors, stemming from what I think is a type issue.

data _null_;
    set Work.row1;
    call execute('%sqlloop(17,'||strip(empl_nbr_var)||','||strip(fleet)||','||strip(base)||','||strip(position)||');');
run;

ignore the 17 part for now just assume thats correct

The first error I get is below, and all other errors seem to stem from that table not being created.

ERROR: The following columns were not found in the contributing tables: A, CHS.

note that there is no quotes around A or CHS, which I believe there should be? Still new to SAS so the not super familiar but to me it looks like that is the error. Is this something weird with strip(), or something else im missing entirely?

Upvotes: 0

Views: 114

Answers (1)

Tom
Tom

Reputation: 51566

To the macro processor everything is text. So in your manual call you have included quotes in the values of the macro parameters. And in the CALL EXECUTE() statement you did not.

You can either re-write the macro to not require the quotes in the values. For example replace references like &fleet. with "&fleet.".

Or add the quote when generating the macro call.

data _null_;
  set work.row1;
  call execute(cats('%sqlloop(17,',quote(trim((empl_nbr_var))
                   ,',',quote(trim(fleet))
                   ,',',quote(trim(base))
                   ,',',quote(trim(position))
                   ,');'
  ));
run;

Upvotes: 1

Related Questions