Hi,
I am running a do until condition and I want the output at the end of each iteration to be added to the same dataset ie.
%macro ..;
%do %until ();
more processing....
data x y;
if ...output x;
else output y;
end;
%mend.
What I am looking to do is at the end of each do until iteration, one dataset that meets the condition is generated and I want to keep adding records to it as I go through the do loop in each iteration. How is this possible?
Each loop iteration is going to replace both data sets X and Y as currently written. You may need to decide on desired data set names for the final result. Then us Proc Append to add x and y to the final set within each loop.
Something conceptually like:
%macro ..; %do %until (); /*more processing....*/ data x y; if ...output x; else output y; run; proc append base=finalx data=x; run; Proc append base=finaly data=y; run; %end; %mend.
Note, your current data steps would not have generated anything as there is nothing providing values that I can see, such as a SET statement.
This assumes that the variables in the X and Y data sets will be the same name, type and length each time. Otherwise you really need to provide examples as appending random stuff runs into issues of variable type compatibility and lengths of character variables.
It is an extremely good idea in macro programming to explicitly end every data step or procedure properly with Run or Quit statements.
You really should provide some example data and what you expect the output to look like.
Each loop iteration is going to replace both data sets X and Y as currently written. You may need to decide on desired data set names for the final result. Then us Proc Append to add x and y to the final set within each loop.
Something conceptually like:
%macro ..; %do %until (); /*more processing....*/ data x y; if ...output x; else output y; run; proc append base=finalx data=x; run; Proc append base=finaly data=y; run; %end; %mend.
Note, your current data steps would not have generated anything as there is nothing providing values that I can see, such as a SET statement.
This assumes that the variables in the X and Y data sets will be the same name, type and length each time. Otherwise you really need to provide examples as appending random stuff runs into issues of variable type compatibility and lengths of character variables.
It is an extremely good idea in macro programming to explicitly end every data step or procedure properly with Run or Quit statements.
You really should provide some example data and what you expect the output to look like.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.