0% found this document useful (0 votes)
291 views6 pages

Proc Append: Proc Append Base Sas Dataset Data Sasdataset Run

The PROC APPEND procedure is used to append observations from one dataset to the end of another dataset. It checks for matching variable types and lengths between the base and data datasets. If mismatches are found, a warning is generated and appending may fail unless the FORCE option is used. FORCE appends the datasets regardless of anomalies but may truncate or drop mismatched variables. The document provides examples of appending with different variable conditions and the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
291 views6 pages

Proc Append: Proc Append Base Sas Dataset Data Sasdataset Run

The PROC APPEND procedure is used to append observations from one dataset to the end of another dataset. It checks for matching variable types and lengths between the base and data datasets. If mismatches are found, a warning is generated and appending may fail unless the FORCE option is used. FORCE appends the datasets regardless of anomalies but may truncate or drop mismatched variables. The document provides examples of appending with different variable conditions and the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

_____________________________________________________________________________________

PROC APPEND
This procedure is used when you want to append observations from one
dataset on the end of the dataset.
Syntax:-
PROC APPEND BASE= SAS DATASET
DATA=SASDATASET;
RUN;
NOTE: - Datasets can be appending by using set statement in dataset, but proc append
can be efficient sometimes when large datasets are involved.
Options:-
Force This is an optional specification that forces proc append to concatenate
datasets. When we used this append the datasets force by without checking any
conditions like present of variables, differences in the variable datasets and length.

Examples:-
Data ds1;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date date9. ;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 11Jan2011
103 asp-15mg f 11Jan2011
101 asp-05mg f 11Jan2011
102 asp-10mg m 12Jan2011
101 asp-05mg m 12Jan2011
102 asp-10mg m 12Jan2011
;
Run;
Data ds2;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 13Jan2011
102 asp-10mg m 13Jan2011
103 asp-15mg f 13Jan2011
104 asp-20mg m 13Jan2011
;
Run;
Proc append base=ds1 data=ds2 ;
Run;
Rule (1) Base dataset contain the variables but not in data
Prints results and gives warning

_____________________________________________________________________________________

NOTE: Appending WORK.DS2 to WORK.DS1.
WARNING: Variable Sex was not found on DATA file.
NOTE: There were 4 observations read from the data set WORK.DS2.
NOTE: 4 observations added.
NOTE: The data set WORK.DS1 has 14 observations and 4 variables.
Without force or with force it gives same result.
Data ds1;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date ;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 11Jan2011
103 asp-15mg f 11Jan2011
101 asp-05mg f 11Jan2011
102 asp-10mg m 12Jan2011
101 asp-05mg m 12Jan2011
102 asp-10mg m 12Jan2011
;
Run;
Data ds2;
Infile Datalines;
Input P_id Drug_name$ Visit_date;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg 13Jan2011
102 asp-10mg 13Jan2011
103 asp-15mg 13Jan2011
104 asp-20mg 13Jan2011
;
Run;
Without force
Proc append base=ds1 data=ds2 ;
Run;

With force
Proc append base=ds1 data=ds2 force ;
Run;

Rule (2) Base dataset doesnt contain the variables but data dataset contain the
variables
NOTE: Appending WORK.DS2 to WORK.DS1.

_____________________________________________________________________________________

WARNING: Variable age was not found on BASE file. The variable will not be added to the
BASE file.
ERROR: No appending done because of anomalies listed above.
Use FORCE option to append these files.
NOTE: 0 observations added.
NOTE: The data set WORK.DS1 has 10 observations and 4 variables.
NOTE: Statements not processed because of errors noted above.
After using force option appending done but Variable age was not found on
BASE file. The variable will not be added to the BASE file.
Data ds1;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date ;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 11Jan2011
103 asp-15mg f 11Jan2011
101 asp-05mg f 11Jan2011
102 asp-10mg m 12Jan2011
101 asp-05mg m 12Jan2011
102 asp-10mg m 12Jan2011
;
Run;
Data ds2;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date age;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 13Jan2011 23
102 asp-10mg m 13Jan2011 25
103 asp-15mg f 13Jan2011 28
104 asp-20mg m 13Jan2011 30
;
Run;
Without force
Proc append base=ds1 data=ds2 ;
Run;
With force
Proc append base=ds1 data=ds2 force;
Run;
Rule (3) Variables of different lengths.
NOTE: Appending WORK.DS2 to WORK.DS1.
WARNING: Variable Drug_name has different lengths on BASE and DATA files
(BASE 10 DATA 8).
NOTE: There were 4 observations read from the data set WORK.DS2.

_____________________________________________________________________________________

NOTE: 4 observations added.
NOTE: The data set WORK.DS1 has 14 observations and 4 variables.

After using force appending done but length is equal to base data variable length
Data ds1;
Infile Datalines;
Length Drug_name$10. ;
Input P_id Drug_name$ Sex$ Visit_date ;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 11Jan2011
103 asp-15mg f 11Jan2011
101 asp-05mg f 11Jan2011
102 asp-10mg m 12Jan2011
101 asp-05mg m 12Jan2011
102 asp-10mg m 12Jan2011
;
Run;
Data ds2;
Infile Datalines;
Length Drug_name$8. ;
Input P_id Drug_name$ Sex$ Visit_date age;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 13Jan2011 23
102 asp-10mg m 13Jan2011 25
103 asp-15mg f 13Jan2011 28
104 asp-20mg m 13Jan2011 30
;
Run;
Without force
Proc append base=ds1 data=ds2 ;
Run;
With force
Proc append base=ds1 data=ds2 force;
Run;
Rule (4) Variables of different data types.
Data ds1;
Infile Datalines;
Input P_id$ Drug_name$ Sex$ Visit_date ;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;

_____________________________________________________________________________________

101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 10Jan2011
102 asp-10mg m 10Jan2011
101 asp-05mg f 11Jan2011
103 asp-15mg f 11Jan2011
101 asp-05mg f 11Jan2011
102 asp-10mg m 12Jan2011
101 asp-05mg m 12Jan2011
102 asp-10mg m 12Jan2011
;
Run;
Data ds2;
Infile Datalines;
Input P_id Drug_name$ Sex$ Visit_date age;
Informat Visit_date date9.;
Format Visit_date date9.;
Datalines;
101 asp-05mg f 13Jan2011 23
102 asp-10mg m 13Jan2011 25
103 asp-15mg f 13Jan2011 28
104 asp-20mg m 13Jan2011 30
;
Run;
Without force
Proc append base=ds1 data=ds2 ;
Run;
NOTE: Appending WORK.DS2 to WORK.DS1.
WARNING: Variable P_id not appended because of type mismatch.
ERROR: No appending done because of anomalies listed above.
Use FORCE option to append these files.
NOTE: 0 observations added.
NOTE: The data set WORK.DS1 has 10 observations and 4 variables.
NOTE: Statements not processed because of errors noted above.

With force
Proc append base=ds1 data=ds2 force;
Run;
NOTE: Appending WORK.DS2 to WORK.DS1.
WARNING: Variable P_id not appended because of type mismatch.
NOTE: FORCE is specified, so dropping/truncating will occur.
NOTE: There were 4 observations read from the data set WORK.DS2.
NOTE: 4 observations added.
NOTE: The data set WORK.DS1 has 14 observations and 4 variables.
So convert both P_id into one data type before appending
Data ds1a(drop=P_id rename=(id1=P_id ));
Set ds1;
id1=input(P_id ,best.);
Run;

_____________________________________________________________________________________


Proc append base=ds1a data=ds2 force ;
Run;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy