DATA Step, Macro, Functions and more

stacking datasets horizontally

Reply
Contributor
Posts: 29

stacking datasets horizontally

How to stack mroe than 2  datasets horizontally ? using sas or PROC SQL .

Respected Advisor
Posts: 2,843

Re: stacking datasets horizontally

In a SAS data set, the MERGE statement allows you to do this.

--
Paige Miller
Super User
Posts: 13,358

Re: stacking datasets horizontally

Example data and desired output for the example data would help.

If the data is to match on some variable(s) it is important to know if the values of the match variables are unique (only one record per data set) or duplicated and if duplicated in which data set(s).

 

When a one-to-one combining often the SAS data step merge is easiest but does require sorting both data sets by the matching variables first.

Contributor
Posts: 29

Re: stacking datasets horizontally

The individual datasets look like in the word file.. and the excel table  is what it should look like :

I was thinknig of using MACROS and merge datastep .. but dont know how to use macros.

 

%macro main(drug, where)  ;

%mend main ;
%main(oni, new_linename EQ 'Onivyde');
%main(fol, new_linename EQ 'FOLFOX');
%main(folnox, new_linename EQ 'FOLFIRINOX');
%main(folfri, new_linename EQ 'FOLFIRI');
%main(gem, new_linename EQ 'Gemcitabine,Paclitaxel Protein-Bound');
%main(all, new_linename in ('Onivyde','FOLFOX','FOLFIRI','FOLFIRINOX','Gemcitabine,Paclitaxel Protein-Bound')

 

datastep :- 

 

data _03_stack ;
merge _03_oni _03_fol _03_folnox _03_folfri _03_gem _03_all ;
by a col ;
run ;

Super User
Posts: 23,357

Re: stacking datasets horizontally

That's a report. If you want the table at the top, look at PROC REPORT or PROC TABULATE for starters. You can find a paper called 'Creating Complex Reports' by Cynthia Zender, it has a lot of good examples and code that illustrate how to get the reports you've shown. 

 


@manya92 wrote:

The individual datasets look like in the word file.. and the excel table  is what it should look like :

I was thinknig of using MACROS and merge datastep .. but dont know how to use macros.

 

%macro main(drug, where)  ;

%mend main ;
%main(oni, new_linename EQ 'Onivyde');
%main(fol, new_linename EQ 'FOLFOX');
%main(folnox, new_linename EQ 'FOLFIRINOX');
%main(folfri, new_linename EQ 'FOLFIRI');
%main(gem, new_linename EQ 'Gemcitabine,Paclitaxel Protein-Bound');
%main(all, new_linename in ('Onivyde','FOLFOX','FOLFIRI','FOLFIRINOX','Gemcitabine,Paclitaxel Protein-Bound')

 

datastep :- 

 

data _03_stack ;
merge _03_oni _03_fol _03_folnox _03_folfri _03_gem _03_all ;
by a col ;
run ;


 

Super User
Posts: 13,358

Re: stacking datasets horizontally

Your word document shows reports, not data sets. You might be much better off finding the data sets used to create the report tables, combine those and make a new report from the combined data.

Especially since the two tables you show in your document do not look alike.

Or show what your actual datasets look like as that document may be very misleading.

 

 

Respected Advisor
Posts: 2,843

Re: stacking datasets horizontally

I don't see any compelling reason to use a macro here. But if it is already written ...

--
Paige Miller
Ask a Question
Discussion stats
  • 6 replies
  • 96 views
  • 2 likes
  • 4 in conversation