@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.
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 |
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;
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
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.