Help using Base SAS procedures

Appending/Set datasets issue

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Appending/Set datasets issue

Hi monthly I will receive weekly datasets like XYZ_WK1,   XYZ_WK2. few months I will receive 4 and few months 5. when I use SET/APPEND to Append data to Base table when one file is missed showing error message how to over come irrespective of datasets number need to append all data sets which are available.

data SOURCE.XYZ ;

set TARGET.XYZ_wk1

     TARGET.XYZ_wk2

     TARGET.XYZ_wk3

     TARGET.XYZ_wk4

     TARGET.XYZ_wk5

  ;

run;

or

proc append base=SOURCE.XYZ data=TARGET.XYZ_wk1;

run;

proc append base=SOURCE.XYZ data=TARGET.XYZ_wk2;

run;

proc append base=SOURCE.XYZ data=TARGET.XYZ_wk3;

run;

proc append base=SOURCE.XYZ data=TARGET.XYZ_wk4;

run;


Accepted Solutions
Solution
‎04-24-2014 10:41 PM
PROC Star
Posts: 7,416

Re: Appending/Set datasets issue

Here is one way:

proc sql noprint;

  select catx('.',libname,memname)

    into :files separated by ' '

      from dictionary.tables

        where libname="TARGET" and

              memname like "XYZ%"

  ;

quit;

data target.xyz;

  set &files.;

run;

View solution in original post


All Replies
Solution
‎04-24-2014 10:41 PM
PROC Star
Posts: 7,416

Re: Appending/Set datasets issue

Here is one way:

proc sql noprint;

  select catx('.',libname,memname)

    into :files separated by ' '

      from dictionary.tables

        where libname="TARGET" and

              memname like "XYZ%"

  ;

quit;

data target.xyz;

  set &files.;

run;

Super User
Super User
Posts: 6,694

Re: Appending/Set datasets issue

I think your list of dataset names will need to include the libname.

select catx('.',libname,memname) ....

PROC Star
Posts: 7,416

Re: Appending/Set datasets issue

Tom,

You are absolutely correct, me bad, and I corrected my original post based on your post.  As for the wild card, I didn't suggest it as (as I recall) that was only made available as of 9.3

Art

Super User
Super User
Posts: 6,694

Re: Appending/Set datasets issue

If your names all start with the same prefix then you could use a wildcard in the SET statement.  (Note your LIBREF names seems backwards to me so I have reversed them in my example code below).

data target.xyz ;

  set source.xyz_wk: ;

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 227 views
  • 0 likes
  • 3 in conversation