0

I have program with data sets and proc sql. At the end of the program I would like to check final value and decide if the part of the program should be executed again with different parameters or the value is ok.

Is there a way I can do loop datasets and procsql ? (For example I want to repeat all the code below.)

proc sql;
    create table first as
    select * from qw;
quit;

data st;
  a = 1
run;

proc sql;
    create table st as
    select * from fir;
quit;

Many thanks for any help. Michal

Reeza
  • 20,510
  • 4
  • 21
  • 38
mical
  • 3
  • 1
  • It looks like you need a macro, where you can add parameters to feed into the data steps / proc sqls. Have you looked into this approach? You don't say what parameters should change, so it's hard to provide a complete answer. There's plenty of help online with macros, so give that a go first and revise your question if you get stuck again – Longfish May 09 '16 at 08:14
  • If I understand you I should rewrite my data steps/proc sql into macro and call them until I find parameter I am ok with? – mical May 09 '16 at 13:41
  • You can add a loop to your macro until it hits a certain value/threshold. – Reeza May 09 '16 at 15:42

1 Answers1

0

You need to create a macro, with a do-while loop. You don't specify what the values are, where you're getting them from or how you want to stop, but hopefully this idea is enough to get you started.

If you are looking at a minimization or optimization problem and have SAS/IML or SAS/OR you may want to see if they have procs that would be helpful for your situation.

%macro loop (threshold);
%do %while (&value < &threshold);
proc sql;
    create table first as
    select * from qw;
quit;

data st;
  a = 1
run;

proc sql;
    create table st as
    select soucet +1 into :value from fir;
quit;


%end;

%mend;

Edit:

Use end= option on the set statement. If its the last record create a macro variable that can be used to loop.

Set end=eof; 
if eof then do; 
    call symputx('soucet', soucet);
end;
Reeza
  • 20,510
  • 4
  • 21
  • 38
  • The code I have is to large, but the basic idea is that I have table similar to below and if soucet is <0 I want to add 1 to plus and do it again. Now I do not know how to get last value of soucet from table2 `%macro table; data table1; do i=1 to 10; plus = 1; minus = 5; output; end; run; data table2; set table1; retain soucet(0); soucet = soucet + plus - minus; output; run; %mend;` – mical May 10 '16 at 07:59
  • Use end= option on the set statement. If its the last record create a macro variable that can be used to loop. Set end=eof; if eof then do; call symputx('soucet', soucet); end; – Reeza May 10 '16 at 09:27