BookmarkSubscribeRSS Feed
Pradeepbanu
Obsidian | Level 7

I have metrics sas table like below

work.met_table
Metrics_Id   Metrics_desc
     1       Count_Column
     2       Sum_Column
     3       Eliminate_column

I wanna do something like doing while loop in T-sql

select count(*) :cnt_tbl from work.met_table

%let init_cnt = 1

while (&init_cnt = &cnt_tbl)
begin
   select Metrics_desc into :met_nm
   from work.met_table
   where metrics_id = 1

    Insert into some_sas_table
    Select * from another table where Metrics_desc =&met_nm
       /* Here I wanna loop all values in metrics table one by one */
end
%put &init_cnt = &int_cnt+1;

How this can be done in proc sql? Thanks in advance

1 REPLY 1
Kurt_Bremser
Super User

Write the SQL for this part:

Insert into some_sas_table
Select * from another table where Metrics_desc =&met_nm

Once you get it to run for one metrics_desc, replace the value with a macro variable (&met_nm), and wrap it into a macro definition with met_nm as parameter.

Then run that off your met_table with call execute:

data _null_;
set met_table;
call execute('%yourmac(' !! trim(metrics_desc) !! ');');
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 2418 views
  • 0 likes
  • 2 in conversation