The vertical and horizontal combining of data set in sas

Adarsha Regmi
2 min readNov 29, 2021


fig: merge

When we combine dataset vertical we use either concatenate or interleave. Interleave is based upon grouping therefore the individual raw records are sorted before concatenating. this is common when not matched upon key variable. In SAS , the horizontal combination is usually called as merges for combining based upon the common variable.

types of horizontal combining

  • One-to-one reading
  • One-to-one merging
  • Match-merging
Program 1.1data work.OneToOneMM; 
merge BookData.ipums2005basic(firstobs = 3 obs = 6) work.ipums2005Utility(obs = 5);
by Serial;

proc print data = work.OneToOneMM;
var serial state metro hhincome electric gas water fuel;

>> match-merge refers to any merge process that uses one or more BY variables to determine which records to join.

>> a one-to-one match-merge occurs when the BY variables create BY groups that contain at most one observation in every input data set.

>>one to one reading combine information from multiple rows into a single row based on observation number instead of variable values. This means they combine information in the first record from each input data set, even if those records have no information in common

Program 1.2 one to one readingdata work. OneToOneRead;  
set BookData.ipums2005basic(firstobs = 3 obs = 6);
set work.ipums2005Utility(obs = 5);

one to one merge example

Program 1.3 one to one merge (also makes use of obs record along with common variable) <no by statement unlike match-merge >data work.OneToOneMerge;  
merge BookData.ipums2005basic(firstobs = 3 obs = 6) work.ipums2005Utility(obs = 5);