Merging to a dataset with 1 observation (Section 5.7)

Sometimes you may wish to merge a dataset with another that contains only one observation. This may happen when you've used PROC MEANS or another procedure to compute an overall sum or statistic based on all observations in the dataset and now you want to incorporate that value back into the original dataset. To do this, you need to use two SET statements in a particular syntax.

Syntax

DATA newdataset;
  IF _N_ = 1 THEN SET onedata;
  SET original_data;

RUN;


Example
data1:
Class	Name	Score 
 A	John	 75  
 A	Jill	 80 
 B	Paul	 98
 C	Andrea	 86 
 A	Chris	 58  
 C	Don	 68 
 B	Amy	 88
 B	Cathy	 92

PROC MEANS DATA=data1 NOPRINT;
  VAR score;
  OUTPUT OUT=outmean MEDIAN=MedScore MEAN=MeanScore STD=StdScore;

DATA newdata;
  IF _N_ = 1 THEN SET outmean;
  SET data1;
RUN;

newdata:
Class	Name	Score	MedScore    MeanScore    StdScore
 A	John	 75  	  83	     80.625	13.1902291
 A	Jill	 80   	  83	     80.625	13.1902291
 B	Paul	 98  	  83	     80.625	13.1902291
 C	Andrea	 86   	  83	     80.625	13.1902291
 A	Chris	 58    	  83	     80.625	13.1902291
 C	Don	 68       83	     80.625	13.1902291
 B	Amy	 88    	  83	     80.625	13.1902291
 B	Cathy	 92    	  83	     80.625	13.1902291

Each observation of newdata now contains the SAME values for the 3 variables output from PROC MEANS.