BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ArchanaSudhir
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION
7 REPLIES 7
ArchanaSudhir
Obsidian | Level 7

If I try this, I am getting

ERROR 180-322: Statement is not valid or it is used out of proper order

 

ArchanaSudhir
Obsidian | Level 7

  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.

Kurt_Bremser
Super User

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.

ArchanaSudhir
Obsidian | Level 7

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

Kurt_Bremser
Super User

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-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
  • 7 replies
  • 1283 views
  • 1 like
  • 2 in conversation