



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Davenport; Class: INTRO TO STATISTICAL COMPUTING; Subject: Statistics; University: Virginia Commonwealth University; Term: Unknown 1989;
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Writing Observations to Multiple SAS Data Sets The SAS system allows you to create multiple SAS data sets in a single data step. The basic tool is the “output” statement. The basic syntax is OUTPUT <sas-data-set-name>; If you use an “output” statement without specifying a data set name, SAS will output that observation to data sets named in the current Data statement. If you want to write to a specific data set, then it must be named in the “output” statement. Any data set named in an “output” statement MUST be listed in the Data statement. Suppose you want to output two data sets; one with guide = ‘Lucas’ and one with guide = ‘other’. (See program SAS_Output1_arts.sas) Note that when you create more than one data set in a Data Statement, the last one listed will be the most recently used data set and hence will be the current work.dataset (in this case, othrtour). To use another data set in a procedure, you must use the “DATA=sas.data.set.name” option. Using an output statement suppresses the automatic output of observations at the end of a DATA step. Therefore, if you plan to use an output statement in a DATA step, then you must program ALL output for that step with output statements. (See program SAS_Output2_arts.sas)
Understanding the OUTPUT Statement An output statement tells the SAS system to output the observation when the output statement is processed, NOT at the end of the DATA Step. This can cause problems, if you are not careful. (See program SAS_Output3_arts.sas) The problem with the example is that the assignment statement that computes the variable “days” is misplaced in the programming stream. (See program SAS_Output4_arts.sas) After the SAS system processes an OUTPUT statement, the observation remains in the program data vector; so you can still continue to program with that observation. You can even output it again to the same SAS data set or to a different one. (See program SAS_Output5_arts.sas)
If the values of the variable consist of only letters, then the sorting is done alphabetically (in ascending order by default). If you omit the “out=newone” options, the sorted version of the data set is named old.one and becomes the current version (i.e., it is replaced). The SORT Procedure provides a message in the SAS log that tells you that the sort procedure was executed. (See program SAS_Sort1_tourtypes.sas) Grouping BY More Than One Variable First variable is sorted, then within the first the second is sorted, then with those the third is sorted, …. Etc. (See program SAS_Sort2_tourtypes.sas) Arranging in Descending Order proc sort data=old.one out=newone; by descending tourtype vendor landcost; run;
Finding the First or Last Observation in a Group Suppose you want to create a data set containing the least expensive tour that features architecture and the least expensive tour featuring scenery. How do you do this without first displaying the data set and seeing which observation to select? First sort by TOURTYPE and LANDCOST. When you use a BY statement, the SAS system automatically creates two additional variables (that are “hidden” variables) for each variable in the BY statement.