Pages

Saturday, August 10, 2013

Widgets

Creating SAS dataset using datalines gives error if written inside a macro

The error is something like this:

ERROR: The macro X generated cards (data lines) for the DATA step which could cause incorrect results.
The DATA step and macro will stop executing.

The solution is to insert the values in a table using proc sql.
The sample code below demonstrates the same.

options nomlogic mprint nosymbolgen;

%macro insertData;
proc sql;
create table class
(Semester char(25) ,
Professor char(24),
Location char(12),
Cost num(5));
quit;
proc sql;
insert into class
(Semester,Professor,Location, Cost)
values('Fall','Dr. Armstrong','London',3000)
values('Spring','Dr. Armstrong','Prague', 3300)
values('Spring','Dr. Hannity','Beijing',3000)
values('Fall','Dr. Hannity','London',3000)
values('Spring','Dr. Smith','Prague',3300)
values('Fall','Dr. Smith','Los Angeles',3800)
;
quit;
%mend insertData;
%insertData;

No comments:

Post a Comment