HI,
I am trying to concatenate 3 datasets (QCdata_1, qcdata_2, qcdata_3) with same structure.
If I try
%MACRO DO_SET;
%DO I = 1 %TO 4;
DATA finalQC;
APPEND Qcdata_&I;
%END;
%MEND DO_SET;
%DO_SET;
It is fiving me error for append.
If I try SET only the last dataset is retained.
Please help.
Thanks,
Archana
Do this:
%macro do_set;
data finalqc;
set
%do i = 1 %to 4;
qcdata_&i
%end;
;
run;
%mend;
%do_set;
Do this:
%macro do_set;
data finalqc;
set
%do i = 1 %to 4;
qcdata_&i
%end;
;
run;
%mend;
%do_set;
If I try this, I am getting
ERROR 180-322: Statement is not valid or it is used out of proper order
DATA finalQC;
6905 SET
6906 %DO I = 1 %TO 4;
6907 Qcdata_qc_t&I ;
6908 %END;
6909 RUN;
6910 %MEND DO_SET;
6911
6912 %DO_SET;
MLOGIC(DO_SET): Beginning execution.
MPRINT(DO_SET): DATA finalQC;
MLOGIC(DO_SET): %DO loop beginning; index variable I; start value is 1; stop value is 4; by value is
1.
SYMBOLGEN: Macro variable I resolves to 1
MPRINT(DO_SET): SET Qcdata_qc_t1 ;
MLOGIC(DO_SET): %DO loop index variable I is now 2; loop will iterate again.
SYMBOLGEN: Macro variable I resolves to 2
NOTE: Line generated by the macro variable "I".
1 Qcdata_qc_t2
---------------------------
180
MPRINT(DO_SET): Qcdata_qc_t2 ;
MLOGIC(DO_SET): %DO loop index variable I is now 3; loop will iterate again.
SYMBOLGEN: Macro variable I resolves to 3
NOTE: Line generated by the macro variable "I".
1 Qcdata_qc_t3
---------------------------
180
MPRINT(DO_SET): Qcdata_qc_t3 ;
MLOGIC(DO_SET): %DO loop index variable I is now 4; loop will iterate again.
SYMBOLGEN: Macro variable I resolves to 4
NOTE: Line generated by the macro variable "I".
1 Qcdata_qc_t4
---------------------------
180
MPRINT(DO_SET): Qcdata_qc_t4 ;
MLOGIC(DO_SET): %DO loop index variable I is now 5; loop will not iterate again.
MPRINT(DO_SET): RUN;
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FINALQC may be incomplete. When this step was stopped there were 0
observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
MLOGIC(DO_SET): Ending execution.
Look again at my proposed solution, and compare it to your code.
You will find that you added a semicolon (that does not belong there) in your log line 6907.
As an exercise in macro programming, try to find out why it must not be there.
Thanks a lot!
I think ; should not be included becasue the format to concatenate datasets is:
DATA xyz;
Set a b c d ;
Set, followed by all datase's name folllowed by ';'
Thanks,
Archana
Well done, young padawan!
😉
This is why I always put macro statements (that need a semicolon to complete) and text that will be created by the macro on separate lines.
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.