DATA Step, Macro, Functions and more

lloop through a dataset

Reply
Occasional Contributor
Posts: 8

lloop through a dataset

Hi all,

First of all, i want to apologize for my poor english.

I want to loop through a SAS data set and i don't know how.
I pass the id to the macro updateValueById, but this not work because it pass a bundle of id, i just want to update id by id.

There is my code:

%MACRO UpdateData;
DATA dataset;
INFILE "c:\employes.txt"
DLM = '09'X
MISSOVER
FIRSTOBS = 2
DSD;
LENGTH id 8
firstname $ 25
lastname $ 25
hire_date 8;

INPUT id
firstname
lastname
hire_date;

%UpdateValueById(id=Id);

RUN;
%MEND UpdateData;

%MACRO %UpdateValueById(Id);
proc sql;
update dataset
set name = 'toto'
where id = &Id;
quit;
%MEND UpdateValue;


Thank you all
PROC Star
Posts: 1,561

Re: lloop through a dataset

You can't call SQL statements to run inside a datastep.

You probably don't need a macro here. Use just SQL, or a merge statement in a data step if tables are/can be sorted, or a hash table if not.
Super Contributor
Posts: 318

Re: lloop through a dataset

Hi Darth,

use the call execute statement in your statement

call execute('%UpdateValueById(id=' || id || ')');

hope this solves your problem.

Regards,
Milton
Occasional Contributor
Posts: 8

Re: lloop through a dataset

Thanks a lot Milton, it work fine.

Best Regards Message was edited by: Darth SAS
Ask a Question
Discussion stats
  • 3 replies
  • 115 views
  • 0 likes
  • 3 in conversation