BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Irena_ik
Fluorite | Level 6

Hello, 

Maybe someone can help me with macro

I need  to get macro like this:  from egtask.report_(&(PLIK&NUM.))   //* it consists with &NUM. - from %do statement (1,3) and &plik(1,3)

 

proc sql; select nr_pliku into:plik1 from pliki_1 where poreczenia=1 ;quit;   //* here I have into:plik1 =3
proc sql; select nr_pliku into:plik2 from pliki_1 where poreczenia=2 ;quit; //* here I have into:plik2 =1
proc sql; select nr_pliku into:plik3 from pliki_1 where poreczenia=3 ;quit; //* here I have into:plik3 =2  

///*parametrs plik1/2/3 in this macro will change therefore I need this macro in loop

 

%macro sqlloop(start,end);
%DO NUM=&start. %TO &end.;
PROC SQL;
create table title&NUM. as select *  
FROM egtask.report_(&(PLIK&NUM.).)      ///* when &NUM.=1 then &plik1, when &NUM.=2 then &plik2.
;QUIT;
%END;
%mend;

%sqlloop(start=1, end=3)

 

Thank You in advance 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

please try (&&PLIK&NUM.) 

 

%macro sqlloop(start,end);
%DO NUM=&start. %TO &end.;
PROC SQL;
create table title&NUM. as select *  
FROM egtask.report_(&&PLIK&NUM.)      ///* when &NUM.=1 then &plik1, when &NUM.=2 then &plik2.
;QUIT;
%END;
%mend;

%sqlloop(start=1, end=3)
Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

please try (&&PLIK&NUM.) 

 

%macro sqlloop(start,end);
%DO NUM=&start. %TO &end.;
PROC SQL;
create table title&NUM. as select *  
FROM egtask.report_(&&PLIK&NUM.)      ///* when &NUM.=1 then &plik1, when &NUM.=2 then &plik2.
;QUIT;
%END;
%mend;

%sqlloop(start=1, end=3)
Thanks,
Jag
Irena_ik
Fluorite | Level 6

Thank You very much!

ed_sas_member
Meteorite | Level 14

Hi @Irena_ik 

 

I believe that the parenthesis prevents the macro resolution: &(PLIK&NUM.).) 

Please try &&PLIK.&NUM. instead.

Best,

 

Irena_ik
Fluorite | Level 6

Thank You for help!

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
  • 4 replies
  • 912 views
  • 2 likes
  • 3 in conversation