Reputation: 307
I'm trying to modify a number of datasets (their names follow a certain order, like data_AXPM061203900_20120104 , data_AXPM061203900_20120105, data_AXPA061204100_20120103, data_AXPA061204100_20120104) under work library. For example, I want to delete variable "price=0" in all datasets.
I am using the following to create a table to identify the datasets:
proc sql ;
create table data.mytables as
select *
from dictionary.tables
where libname = 'WORK'
order by memname ;
quit ;
For the next step, I'm trying to use a macro:
%macro test;
proc sql ;
select count(memname) into: obs from data.mytables;
%let obs=&obs.;
select catx("_", "data", substr(memname, 6, 13), substr(memname,20,27))
into :setname1-:setname&obs.
from data.mytables;
quit;
%do i=1 %to &obs.;
data &&setname&i
set &&setname&i
if bid_price= '.' then delete;
%end;
%mend test;
However, it completely failed. Could anyone give me some suggestions? I'm really not good at macros. Errors include:
Upvotes: 1
Views: 439
Reputation: 6378
You are missing semicolons on the DATA statement and SET statement, and should probably add a RUN statement. Suggest you try:
%do i=1 %to &obs.;
data &&setname&i ;
set &&setname&i ;
if bid_price= '.' then delete;
run;
%end;
Note that the DELETE statement is deleting records, not deleting variables. The code above expects that bid_price is a character variable, and that you want to delete records when the value is '.'.
Upvotes: 1