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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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