I have a dataset(data_1) and I want to append all the data from this dataset to a new dataset(data_2) one by one and also delete the data which I have appended into data_2 from data_1 until the data_1 becomes empty,so it's basically a kind of Cut&Paste
so I am using the following approach
do i=1 to 1000000;
append base=data_2 data=data_1;
..............
end;
But i want to stop this loop as soon as soon as the data_1 becomes empty just to avoid unnecessary looping,
so please suggest me a solution to insert just before the end statement
i am providing the pseudocode
do i=1 to 1000000;
append base=data_2 data=data_1;
..............
if(data_1 = empty)
then stop;
end;
This is just what i am trying to do, it's not the exact code
so please suggest me some solution to write the code using the Leave command.
Please stop posting topics with the title "Base SAS". The topic title is supposed to be a summary of the question.
With regards to your question, why are you appending a dataset row by row in a loop? To append data to an existing dataset you would use the procedure designed for the task:
proc append base=base data=new_data; run;
Alternatively you can set data underneath and create a new dataset:
data want; set old_data new_data; run;
Well, one can do
data test;
x1 = 0;
do i = 1 to 10000;
x1 = x1 + 2;
end;
drop i;
run;
or one can do
data test;
x1 = 10000 * 2;
run;
I clearly prefer method #2, and you should do the same and run one single append as @RW9 already suggested.
Another case where short examples of your input data sets and what the result should look like as indicated in the "how to post a good question" reminders.
Interleaving (like shuffling a deck of cards ) and appending (placing one half of the deck on top of the other) are two different concepts. Since your code isn't executeable it really isn't clear which you are attempting.
Note if you use a data step loop such as do i= 1 to n. You can conditionally terminate the loop early with the LEAVE instruction such as:
do i = 1 to 1000;
<some code>;
if varx > 25 then leave;
end;
would terminate when the value of varx is greater than 25. Which would in context only make sense if the other code is modifying varx in some manner.
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.