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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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