How to stack mroe than 2 datasets horizontally ? using sas or PROC SQL .
In a SAS data set, the MERGE statement allows you to do this.
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.
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 ;
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 ;
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.
I don't see any compelling reason to use a macro here. But if it is already written ...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.