DATA Step, Macro, Functions and more

PROC APPEND FROM MULTIPLE TABLE

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

PROC APPEND FROM MULTIPLE TABLE

I want to append all dataset into one (using proc append) I'm using below code, but not giving output

 

Please help !!

 


proc sql;
select count(*) into : obs from sashelp.vtable
where libname = 'ABC';

%LET OBS=&OBS;
SELECT memname INTO : TAB1-:TAB&OBS FROM sashelp.vtable
where libanme = 'ABC';

QUIT;

%MACRO append;
%DO i=1 %to &obs;
proc append base=tot_comb data=&&tab&i force;run;
%end;
%mend;

%append;


Accepted Solutions
Solution
‎05-31-2017 08:54 AM
Super User
Posts: 17,865

Re: PROC APPEND FROM MULTIPLE TABLE

Uh...you should probably fix those errors from the first proc? 

 

Take a a look at the table and and make sure your query is correct. I'm not in front of a computer with SAS to answer the actual column name. 

View solution in original post


All Replies
Super User
Posts: 17,865

Re: PROC APPEND FROM MULTIPLE TABLE

Are you getting errors? 

 

Pleae explain how it isn't working. 

 

Make sure to ru it with mprint symbolgen on to see what's happening. 

Contributor
Posts: 60

Re: PROC APPEND FROM MULTIPLE TABLE

 

 

809 proc sql;
810 select count(*) into : obs from sashelp.vtable
811 where libname = 'ABC';
812 %LET OBS=&OBS;
SYMBOLGEN: Macro variable OBS resolves to 3
813 SELECT memname INTO : TAB1-:TAB&OBS FROM sashelp.vtable
SYMBOLGEN: Macro variable OBS resolves to 3
814 where libanme = 'ABC';
ERROR: The following columns were not found in the contributing tables: libanme.
815 QUIT;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.13 seconds
cpu time 0.03 seconds

816 %MACRO append;
817 %DO i=1 %to &obs;
818 proc append base=tot_comb data=&&tab&i force;run;
819 %end;
820 %mend;
821 %append;
MLOGIC(APPEND): Beginning execution.
SYMBOLGEN: Macro variable OBS resolves to 3
MLOGIC(APPEND): %DO loop beginning; index variable I; start value is 1; stop value is 3; by value is
1.


SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
NOTE: Line generated by the macro variable "I".
1 &tab1
-
22
200
WARNING: Apparent symbolic reference TAB1 not resolved.
ERROR: File WORK.TAB1.DATA does not exist.
MPRINT(APPEND): proc append base=tot_comb data=&tab1 force;
MPRINT(APPEND): run;

ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

NOTE: The SAS System stopped processing this step because of errors.
MLOGIC(APPEND): %DO loop index variable I is now 2; loop will iterate again.


SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 2
NOTE: Line generated by the macro variable "I".
1 &tab2
-
22
200
WARNING: Apparent symbolic reference TAB2 not resolved.
ERROR: File WORK.TAB2.DATA does not exist.
MPRINT(APPEND): proc append base=tot_comb data=&tab2 force;
MPRINT(APPEND): run;

ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
MLOGIC(APPEND): %DO loop index variable I is now 3; loop will iterate again.


SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 3
NOTE: Line generated by the macro variable "I".
1 &tab3
-
22
200
WARNING: Apparent symbolic reference TAB3 not resolved.
ERROR: File WORK.TAB3.DATA does not exist.
MPRINT(APPEND): proc append base=tot_comb data=&tab3 force;
MPRINT(APPEND): run;

ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
MLOGIC(APPEND): %DO loop index variable I is now 4; loop will not iterate again.
MLOGIC(APPEND): Ending execution.

 

Solution
‎05-31-2017 08:54 AM
Super User
Posts: 17,865

Re: PROC APPEND FROM MULTIPLE TABLE

Uh...you should probably fix those errors from the first proc? 

 

Take a a look at the table and and make sure your query is correct. I'm not in front of a computer with SAS to answer the actual column name. 

Contributor
Posts: 60

Re: PROC APPEND FROM MULTIPLE TABLE

yeah...i got the output..thanks...but just a quick question (I was missing that base table should have same schema similar to data from which i'm appending) :

proc sql;
select count(*) into : obs from sashelp.vtable
where libname = 'ABC';
%LET OBS=&OBS;
SELECT catx('.', 'abc', memname) INTO : TAB1-:TAB&OBS FROM sashelp.vtable
where libname = 'ABC';
QUIT;
%MACRO append;
%DO i=1 %to &obs;
proc append base=tot_comb data=&&tab&i force;run;
%end;
%mend;
%append;

proc print data=tot_comb;
run;
Super User
Posts: 6,946

Re: PROC APPEND FROM MULTIPLE TABLE

And what is the question?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 60

Re: PROC APPEND FROM MULTIPLE TABLE

sorry...Its working !!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 2361 views
  • 0 likes
  • 3 in conversation