Hi Everyone, i need to figure out how to loop through a list of numbers using a macro/do loop. I have tried the same approach as a list of variables but that doesn't seem to work at all. I need to run the code for a set of clinic numbers but don't want to have to change the clinic number and run it a million times if it can be avoided. thanks! cat %macro doit(list); %let n=%sysfunc(countw(&list)); %do i=1 %to &n; %let val = %scan(&list,&i); %mend; %doit(124 70 76 57 79 221); proc sql; CONNECT to odbc(dsn=dbwh); CREATE TABLE bftest as SELECT * from connection to odbc ( SELECT P.FileDate, CLINICID, SUM( Mo0Count) as Mo0Count1, Mo0CountTotal, R.PACKET, CASE WHEN convert(float, Mo0CountTotal) > 0 THEN SUM(Mo0Count) / convert(float, Mo0CountTotal) ELSE 0 END as Mo0FEEDPercent FROM dbo.BreastfeedingEthnicity as P JOIN dbo.Dates D ON p.FileDate = D.DateText JOIN (SELECT *, CASE WHEN PGLABEL = 'IB -BF Fully' THEN 'FullyBF' WHEN PGLABEL = 'IF -Formula' THEN 'FORMULA' WHEN PGLABEL IN ('IC -BF Mostly', 'IO -BF Some') THEN 'MOSTSOME' ELSE '' END AS PACKET FROM dbo.PacketGroupReference) as R ON P.PacketGroup = R.PacketGroup JOIN ( SELECT FileDate, SUM(Mo0Count) as Mo0CountTotal FROM dbo.BreastfeedingEthnicity as P WHERE FileDate >= '2017-10' AND AgencyID = 314 AND ClinicID = %doit GROUP BY CLINICID, FILEDATE ) as T ON P.FileDate = T.FileDate WHERE P.FileDate >= '2017-10' AND AGENCYID =314 AND CLINICID = %doit GROUP BY CLINICID, P.FileDate, Mo0CountTotal, PACKET ORDER BY CLINICID, P.FILEDATE ); %end; quit;
... View more