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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 633 views
  • 0 likes
  • 3 in conversation