data l2;
input id $;
cards;
c1
c2
c3
run;
proc sql;
select count(*) into:emailtblcnt from l2;
quit;
In this the macro varibale at a time should hold one value if we run this at one instance the macro ids should have one value. how can i loop it
%macro emicnt;
%do i=1 %to &emailtblcnt.;
proc sql;
select id into:ids from l2;
quit;
%put &ids;
%end;
%mend;
%emicnt;
I don't know why would you do this.
data l2; input id $; cards; c1 c2 c3 run; proc sql; select count(*) into:emailtblcnt from l2; quit; %macro emicnt; %do i=1 %to &emailtblcnt.; proc sql; select id into:ids1-:ids&i from l2; quit; %let ids=&&ids&i ; %put &ids; %end; %mend; %emicnt;
The following is simple enough.
proc sql; select id from l2; select id into:ids1-:ids&sqlobs from l2; quit;
Ksharp
R_Win,
Modify the first SQL before you even get to macro language. Add another SELECT statement:
select strip(ids) into : email_list separated by ' ' from I2;
Then inside your macro you can loop:
%do i=1 %to &emailtblcnt;
%let next_id = scan(&email_list, &i, %str( ));
%end;
This approach assumes that the individual values of ID will not contain an embedded blank. If there are embedded blanks, it gets more complicated but can still be done.
Good luck.
I don't know why would you do this.
data l2; input id $; cards; c1 c2 c3 run; proc sql; select count(*) into:emailtblcnt from l2; quit; %macro emicnt; %do i=1 %to &emailtblcnt.; proc sql; select id into:ids1-:ids&i from l2; quit; %let ids=&&ids&i ; %put &ids; %end; %mend; %emicnt;
The following is simple enough.
proc sql; select id from l2; select id into:ids1-:ids&sqlobs from l2; quit;
Ksharp
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!
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.