Selected observations subsetting data data set

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: NBERG DESIREE FirstName JobCode 0040 0071 Salary PILOT 50221.62 WILLIAMS ARLENE M. FLTAT PERRY ROBERT A. FLTAT st.empdata 23666.12 21957.71 PROC Step proc print data=st.empdata noobs; var JobCode EmpID Salary; where JobCode='PILOT'; run; Select rows to print The SAS System Job Code Emp ID Salary PILOT PILOT PILOT PILOT 0031 0082 0355 0366 50221.62 96387.39 59803.16 120202.38 Data set options are applied to data sets resulting in certain actions such as processing the first or last n observations. •FIRSTOBS=n specifies that processing is to start from the nth observation. •OBS=n specifies that processing is to stop after the nth observation. These can be used separately or together. 21 Subsetting Data: Data Set Options Syntax: 22 Requesting Column Totals The SUM statement produces column totals. General form of the SUM statement: … Data-set(data-set option) … SUM variable(s); Applied to data sets in a DATA step statement or PROC step statement: The SUM statement also produces subtotals if you print the data in groups. proc print data=st.empdata(firstobs=2 obs=5); run; 23 24 6 Requesting Column Totals EmpID LastName 0031 GOLDENBERG DESIREE 0040 0071 WILLIAMS PERRY Produce column totals FirstName JobCode Sorting a SAS Data Set Salary PILOT 50221.62 ARLENE M. FLTAT ROBERT A. FLTAT st.empdata 23666.12 21957.71 PROC Step proc print data=st.empdata noobs; var JobCode EmpID Salary; sum Salary; run; The SAS System To request subgroup totals in PROC PRINT, the observations in the data set must be grouped. The SORT procedure • rearranges the observations in a SAS data set • can create a new SAS data set containing the rearranged observations • can sort on multiple variables Job Code Emp ID Salary PILOT FLTAT FLTAT 0031 0040 0071 50221.62 23666.12 21957.71 • can sort in ascending (default) or descending order • does not generate printed output • treats missing values as the smallest possible value. . . ========= 428677.92 25 26 Sorting a SAS Data Set Sorting a SAS Data Set st.empdata General form of the PROC SORT step: EmpID LastName 0031 GOLDENBERG DESIREE 0040 0071 PROC SORT DATA=input-SAS-data-set <OUT=output-SAS-data-set>; BY <DESCENDING> by-variable(s); RUN; FirstName JobCode Salary PILOT 50221.62 WILLIAMS ARLENE M. FLTAT 23666.12 PERRY ROBERT A. FLTAT 21957.71 PROC Step proc sort data=st.empdata out=work.empdata; by JobCode; run; Examples: proc sort data=st.empdata; by Salary; run; work.empdata EmpID FirstName JobCode WILLIAMS ARLENE M. FLTAT 23666.12 0071 PERRY ROBERT A. FLTAT 21957.71 0031 27 LastName 0040 proc sort data=st.empdata out=work.jobsal; by JobCode descending Salary; run; GOLDENBERG DESIREE PILOT Salary 50221.62 28 7 Printing Subtotals and Grand Totals Printing Subtotals and Grand Totals The SAS System ------------------------ JobCode=FLTAT ------------------------- Print the data set grouped by JobCode with a subtotal for the Salary column for each JobCode. proc sort data=st.empdata out=work.empdata; by JobCode;...
View Full Document

Ask a homework question - tutors are online