Overview of Multiple Data Sets.doc

Overview of Multiple Data Sets.doc - Topic Overview of...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Topic: Overview of Multiple Data Sets 1. Concatenating data set using Set statement 2. Interleaving several datasets 3. Modifying (creating) data set 4. Concatenating data set using PROC APPEND 5. Merging datasets 6. Updating dataset 7. PROC EXPORT/IMPORT 8. PROC CONTENTS 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Overview One of SAS’s greatest strengths is its ability to combine and process more than one data set at a time. The main tools used to do this are the SET, MERGE and UPDATE statements. 1. Concatenating data set using Set statement It reads an observation from one or more SAS data sets. The SET statement is flexible and has a variety of uses in SAS programming. These uses are determined by the options and statements that you use with the SET statement: data one; input year pop $ @@; datalines ; 1991 500K 1992 501K 1993 502K ; data two; input year pop $ @@; datalines ; 1991 400K 1992 401K 1993 402K ; data three; input year pop $ @@; datalines ; 1991 300K 1992 301K 1993 302K 1994 303K ; data combine_1; set one two three; run ; data con1; input custom_id $ product $ 12. ; cards ; 28901 pentium IV 36815 pentium III 21224 pentium IV ; data con2; input custom_id $ product $ 12. ; cards ; 18601 pentium IV 24683 pentium III 851921 pentium IV 61831 pentium IV ; data con3; set con1; set con2; run ; 2. Interleaving several datasets If you want to combine several datasets so that observations sharing a common value are all adjacent to each other, you can list the datasets on SET statement, and specify the variable to be used on a BY statement. Note: The data sets to be interleaved must already be sorted by the variable(s) listed in the BY statement. 2
Image of page 2
/*Creating a new data set from multiple data sets based upon sorted order*/; data animal; input common $ animal $; datalines ; a Ant a Ape b Bird c Cat d Dog ; data plant; input common $ plant $; datalines ; a Apple b Banana c Coconut d Dewberry e Eggplant f Fig ; data interleaving; set animal plant; by common; run ; proc print data =interleaving; run ; 3. The SET statement is used to modify an existing SAS data set and Reading Observations Using Direct Access data old; input x1-x3; datalines ; 1 2 3 3 4 5 ; data new; set old; xtot=sum(of x1-x3); run ; data a; input x y @@; cards ; 901 1 902 2 903 3 904 4 905 5 ; data b; x= 2 ; /*select a given obs*/ set a point=x; output ; stop ; run ; 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
To create a temporary numeric variable whose value is used to detect the last observation, you can use the END= option in the SET statement. data en; input accnt balance day @@; cards ; 901 486 1 901 985 4 903 498 2 903 498 2 ; data en2; set en end=last; if last; run ; 4. Concatenating data set using PROC APPEND Concatenating SAS data sets is the process of storing observations one after another until all the data sets and their observations have been combined into one data set. Many users perform the concatenation process using a DATA step (as shown in the previous examples), but there are good reasons for using the APPEND procedure. If you use the SET statement in a DATA step to concatenate two data sets, the SAS System must process all the observations in both data sets to create a new one. The APPEND procedure bypasses the processing of data in the original data set and adds new observations directly to the end of the original data set. It does this by positioning the
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern