BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

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

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
ballardw
Super User

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.

manya92
Fluorite | Level 6

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 ;

Reeza
Super User

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 ;


 

ballardw
Super User

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.

 

 

PaigeMiller
Diamond | Level 26

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

--
Paige Miller

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1282 views
  • 2 likes
  • 4 in conversation