sort proc sort data=datasetname; by variable1 … variablen; print proc print data=datasetname;

4
• There are several PROCs that we can use at this stage in their “default” mode (later we’ll work with many of their options): – PROC SORT; to rearrange data – PROC PRINT; to print out data – PROC MEANS; to compute simple descriptive statistics of numeric variables – PROC FREQ; to compute frequency distributions and cross tabulations of categorical variables

Upload: jada

Post on 07-Jan-2016

25 views

Category:

Documents


2 download

DESCRIPTION

There are several PROCs that we can use at this stage in their “default” mode (later we’ll work with many of their options): PROC SORT; to rearrange data PROC PRINT; to print out data PROC MEANS; to compute simple descriptive statistics of numeric variables - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SORT PROC SORT DATA=datasetname;   BY variable1 … variablen; PRINT PROC PRINT DATA=datasetname;

• There are several PROCs that we can use at this stage in their “default” mode (later we’ll work with many of their options):– PROC SORT; to rearrange data– PROC PRINT; to print out data– PROC MEANS; to compute simple descriptive

statistics of numeric variables– PROC FREQ; to compute frequency

distributions and cross tabulations of categorical variables

Page 2: SORT PROC SORT DATA=datasetname;   BY variable1 … variablen; PRINT PROC PRINT DATA=datasetname;

• SORTPROC SORT DATA=datasetname; BY variable1 … variablen;

• PRINTPROC PRINT DATA=datasetname;

• MEANS PROC MEANS DATA=datasetname;

• FREQPROC FREQ DATA=datasetname;TABLES variable_combinations;

Check out support.sas.com and look for the “documentation” link…

Page 3: SORT PROC SORT DATA=datasetname;   BY variable1 … variablen; PRINT PROC PRINT DATA=datasetname;

• SORTPROC SORT DATA=datasetname; BY variable1 … variablen;

– The BY statement is required for this procedure and gives the name of the variable(s) on which the ordering is to be based. In other procedures, the BY statement is optional and indicates that the PROC is to perform a separate analysis for each combination of levels of the BY-variables instead of as a whole group.

– When doing a PROC by a variable, the dataset must first be SORTed BY that variable - this is one of the main uses of PROC SORT; Let’s do some examples…

Page 4: SORT PROC SORT DATA=datasetname;   BY variable1 … variablen; PRINT PROC PRINT DATA=datasetname;

• Open SAS and read in the “diet program” data…• Show the many ways PROC SORT can be used with

this data… note that SORT does not print automatically - you must use PROC PRINT to see the results of your SORTing…

• Try PROC MEANS & PROC FREQ on this data too to see the results…

• Try these PROCs on BY groups; that is, SORT the data BY an appropriate variable and then do the other PROCs BY that variable and notice the different results that are possible.

• HW: Use Dr. Padgett’s data and practice SORT, PRINT, MEANS, and FREQ. This material can be found in various sections of Chapter 4…