The script begins by creating three datasets (advisees_MPH, advisees_DrPH, advisees_MHA) via DATA step blocks with DATALINES statements to populate the data. It then illustrates the simple concatenation of datasets with identical variables (advisees_MPH and advisees_DrPH into advisees). A second demonstration shows the concatenation of datasets with different variable names (advisees_MPH and advisees_MHA into advisees_Masters), requiring the use of the RENAME option in the SET statement to harmonize the column names 'degree' and 'program'.
Data Analysis
Type : INTERNAL_CREATION
Source data is created directly within the script using DATA step blocks and DATALINES statements.
1 Code Block
DATA STEP Data
Explanation : Creation of the 'advisees_MPH' dataset with 'first', 'gender', and 'program' variables. Data is entered via DATALINES statements.
Copied!
data advisees_MPH;
input first $ gender $ program $;
datalines;
Alison F MPH
Ming F MPH
run;
1
DATA advisees_MPH;
2
INPUT first $ gender $ program $;
3
DATALINES;
4
Alison F MPH
5
Ming F MPH
6
RUN;
2 Code Block
DATA STEP Data
Explanation : Creation of the 'advisees_DrPH' dataset with the same variables as 'advisees_MPH'. Data is entered via DATALINES statements.
Copied!
data advisees_DrPH;
input first $ gender $ program $;
datalines;
Tiffany F DrPH
Florence F DrPH
run;
1
DATA advisees_DrPH;
2
INPUT first $ gender $ program $;
3
DATALINES;
4
Tiffany F DrPH
5
Florence F DrPH
6
RUN;
3 Code Block
DATA STEP
Explanation : Concatenation of 'advisees_MPH' and 'advisees_DrPH' datasets into a new 'advisees' dataset. Since the variables are identical, the merge is direct.
Copied!
data advisees;
set advisees_MPH advisees_DrPH;
run;
1
2
DATA advisees;
3
SET advisees_MPH advisees_DrPH;
4
RUN;
5
4 Code Block
PROC PRINT
Explanation : Displays the content of the 'advisees' dataset, resulting from the first concatenation.
Copied!
proc print data = advisees;
run;
1
PROC PRINTDATA = advisees;
2
RUN;
5 Code Block
DATA STEP Data
Explanation : Creation of the 'advisees_MHA' dataset with 'first', 'gender', and 'degree' variables. The 'degree' variable is intentionally different from 'program' in the previous datasets.
Copied!
data advisees_MHA;
input first $ gender $ degree $;
datalines;
Jessica F MHA
Ryan M MHA
run;
1
DATA advisees_MHA;
2
INPUT first $ gender $ degree $;
3
DATALINES;
4
Jessica F MHA
5
Ryan M MHA
6
RUN;
6 Code Block
DATA STEP
Explanation : Attempt to concatenate 'advisees_MPH' and 'advisees_MHA' datasets. Due to different variable names ('program' and 'degree'), corresponding values will be missing in the resulting dataset where the variable does not exist in the source dataset.
Copied!
data advisees_Masters;
set advisees_MPH advisees_MHA;
run;
1
2
DATA advisees_Masters;
3
SET advisees_MPH advisees_MHA;
4
RUN;
5
7 Code Block
PROC PRINT
Explanation : Displays the content of the 'advisees_Masters' dataset after concatenation without renaming, showing missing values due to different variable names.
Copied!
proc print data = advisees_Masters;
run;
1
PROC PRINTDATA = advisees_Masters;
2
RUN;
8 Code Block
DATA STEP
Explanation : Re-concatenation of 'advisees_MPH' and 'advisees_MHA' datasets. The RENAME option is used to temporarily rename the 'degree' variable from 'advisees_MHA' to 'program' at the time of reading, allowing for correct data concatenation into a single 'program' variable.
Copied!
data advisees_Masters;
set advisees_MPH advisees_MHA (rename = (degree = program));
run;
1
2
DATA advisees_Masters;
3
SET advisees_MPH advisees_MHA (rename = (degree = program));
4
RUN;
5
9 Code Block
PROC PRINT
Explanation : Displays the final content of the 'advisees_Masters' dataset, demonstrating successful concatenation through the use of the RENAME option.
Copied!
proc print data = advisees_Masters;
run;
1
PROC PRINTDATA = advisees_Masters;
2
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.