Desktop productivity for business analysts and programmers

Merge step1 step2 ... step27

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Merge step1 step2 ... step27


Hi all,

is there a way to merge a lot of datsets with increasing suffixes?

data mydataset;

     merge step1 step2 step3 [...] step27;

     by myvar;

run;

is very long to write.

data mydatset;

     merge step1 - step27;

     by myvar;

run;

doesn't work...

any suggestions?


Accepted Solutions
Solution
‎06-02-2014 09:14 AM
Super User
Posts: 7,446

Re: Merge step1 step2 ... step27

With a macro:

data mydataset;

merge

  %macro datasets;

  %do i = 1 %to 27;

  step&i

  %end;

  %mend;

  %datasets

;

by myvar;

run;

But you don't need that, as others already said, the set1-set27 solution works at least in 9.2.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 9,875

Re: Merge step1 step2 ... step27

What version of sas are you using ? I can run your code.

Contributor
Posts: 27

Re: Merge step1 step2 ... step27

SAS enterprise guide

Respected Advisor
Posts: 3,156

Re: Merge step1 step2 ... step27

Merge statement supports data sets lists, so It should work.

Please elaborate more on  "doesn't work...". Did it throw an error message or it didn't work the way you expected? Do you have the log? More details would be helpful.

So you are using the Eguide, but what version? 4.3/5.1 or 6.1?

Regards,

Haikuo

Contributor
Posts: 27

Re: Merge step1 step2 ... step27

IT's 4.1.

It doesn't run at all, just gives an error message.

It's ok though, I've solved it by writing a macro around it as RW9 suggested.

Thanks for your answers

Solution
‎06-02-2014 09:14 AM
Super User
Posts: 7,446

Re: Merge step1 step2 ... step27

With a macro:

data mydataset;

merge

  %macro datasets;

  %do i = 1 %to 27;

  step&i

  %end;

  %mend;

  %datasets

;

by myvar;

run;

But you don't need that, as others already said, the set1-set27 solution works at least in 9.2.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 278 views
  • 0 likes
  • 4 in conversation