BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

@Toni2 wrote:
thanks but my problem is the code for some reason creates duplicates

Remove either the PROC APPEND step or the DATA step and it will not duplicate the data.

Just to spell it out:

You want to either use code like this:

%do i=1 %to 4;
proc append base=data1 data=data_&i force;
run;
%end;

OR code like this

%do i=1 %to 4;
data data1;
   set 
%if &i > 1 %then data1 ; data_&i;
run;
%end;

But don't use both step because then DATA_&I is appended TWICE.

Toni2
Lapis Lazuli | Level 10

i use the PROC Append and works, thanks and sorry for the confusion.
Actually, now what happens is, when i run the code multiple times then the data1 becomes bigger and bigger...any idea how to resolve this? (sorry possibly this is what i missed to explain)

 

Actually, this is what i can see

 

ndex Variable
0.008232 var1
0.003461 var2
0.003461 var2
0.006708 var3
0.006708 var3
0.000037 var4
0.000037 var4
Tom
Super User Tom
Super User

I assume that you just need to REMOVE the old dataset before running the program again.

proc delete data=data1; run;
%do i=1 %to 4;
proc append base=data1 data=data_&i force;
run;
%end;
Toni2
Lapis Lazuli | Level 10

it works again! thanks! When i run this for first time i get a warning that the data1 does not exist. Is there any way to avoid this as well? i ask since this is going to be part of a huge code and i want to avoid warnings/errors

Tom
Super User Tom
Super User

Run it conditionally.

%if %sysfunc(exist(data1)) %then %do;
proc delete data=data1; run;
%end;

Or

Use PROC DATASETS instead.

proc datasets nolist nowarn lib=work;
  delete data1;
run;
quit;
Toni2
Lapis Lazuli | Level 10
Thanks for the support 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 5062 views
  • 8 likes
  • 4 in conversation