BookmarkSubscribeRSS Feed
Himanshu007
Obsidian | Level 7

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.

@PeterClemmensen

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Kurt_Bremser
Super User

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.

ballardw
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 683 views
  • 2 likes
  • 4 in conversation