BookmarkSubscribeRSS Feed
DarthSAS
Calcite | Level 5
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
3 REPLIES 3
ChrisNZ
Tourmaline | Level 20
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.
milts
Pyrite | Level 9
Hi Darth,

use the call execute statement in your statement

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

hope this solves your problem.

Regards,
Milton
DarthSAS
Calcite | Level 5
Thanks a lot Milton, it work fine.

Best Regards Message was edited by: Darth SAS
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1352 views
  • 0 likes
  • 3 in conversation