Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Combining multiple data sets - some missing

Combining multiple data sets - some missing

Combining multiple data sets - some missing

I have about 45000+ small data sets that I need to combine into one data set. I have tried using the macro code below. The problem is that there's  about 50 data sets that are missing and when for instance data set "parm400" is missing the code fails and the "Samletparm" data set contains no observations.
Is there a way to tell SAS to continue joining the data sets even if there's some missing in between?

%macro names(prefix,maxnum);
%do i=1 %to &maxnum;
%mend names;

data eq.SamletParm;
set %names(eq.parm,46080);

Thanks in advance.

RE: Combining multiple data sets - some missing

My first response is to use the PROC APPEND instead of the data-set statements.  The proc will write an ERROR to log but will continue.
My second response is, even using proc append you can check if the dataset exists before you call your proc append code.


%macro combine_names(target_name,prefix,maxnum);
   %do i=1 %to &maxnum;
     %if %sysfunc(exist(&prefix&i)) %then %do;
        proc append
          base = target_name
          data = &prefix&i force;
%mend combine_names;

I changed the name of the macro but I think you can use it the way it is.


RE: Combining multiple data sets - some missing

If you have SAS 9.2, and your datasets follow a named range (as your example suggests) then you can use the colon modifier in the set statement.


*generate dummy datasets ;
data class1 class3 class4 ;
   set sashelp.class ;
   run ;

data all ;
   set class: ;*colon modifier to set datasets with same prefix;

RE: Combining multiple data sets - some missing

Thats true, but if one of the named range datasets are not found that datastep will fail.

RE: Combining multiple data sets - some missing


I agree with you for normal named ranges, i.e name1-nameN. But the prefix modifier example I gave demonstrates that as long as the prefix is the same, it will concatenate all datasets that meet that criteria (the class2 dataset does not exist).


RE: Combining multiple data sets - some missing

Agreed.  The CLASS method would work for known named ranges. But for all other types and if you don't have SAS 9.2 (my current new place does not have it yet) you would need to implement a solution as I have laid out.

Thanks for the CLASS idea though, I will use it in the future.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close