Ordinary Least Squares

In this tutorial, you will learn to describe a dataset using CONTENTS procedure, to sort (double sort and multiple sort) a dataset using the SORT procedure, and print certain results to the log file (screen) using the PRINT procedure.

CONTENTS Procedure

This procedure is used to find the contents (variable names, label, and description) of a SAS data-set.

Click here to download the data. Always place files in the C:\data folder. Also, set C:\data directory as the WORK directory.

To find its contents, run the code below.

SAS code:


proc contents data=work.gdata ;
run ;

Click here to view the html output of the contents. Set C:\data directory as the WORK directory.

To output the contents to a pdf, run the code below.

SAS code:


ods pdf file="C:\data\contents.pdf" ;
 proc contents data=work.gdata ;
  run;
 quit;
ods pdf close;

Click here to view the pdf output of the contents.

Practice Exercises

Find the contents of the following data-sets


SORT Procedure

Ascending sort

This procedure is used to sort variables (or a group of variables) by its values, either in the ascending order or the descending order. Set C:\data directory as the WORK directory.

To sort Dataset 3 by JOURNAL NAME variable in the ascending order, run the code below.

SAS code:


proc sort data = work.jrank ;
 by title ;
run;

Output:

Journal ranking sorted by TITLE

Descending sort

To sort Dataset 3 by JOURNAL RANK variable in the descending order, run the code below. Set C:\data directory as the WORK directory.

SAS code:


proc sort data=work.jrank ;
 by descending rank;
run;

Multiple sort

Now, consider this data. To sort this data first by TICKER, then by descending DATE1, again then by descending DATE2, and create a new dataset TEMP that contains the sorted data; run the code below. Set C:\data directory as the WORK directory.

SAS code:


proc sort data=work.gdata out=work.temp;
 by ticker descending date1 descending date2 ;
run;


Consider this data. To print the values of a variable on-screen (first 15 observations), run the code below. Set C:\data directory as the WORK directory.

SAS code:


proc print data=work.in401k (obs=15);
run;

Click here to view the printed log file in pdf.

To print the values of selected variable on-screen (first 15 observations), run the code below. Set C:\data directory as the WORK directory.

SAS code:


proc print data=in.in401k (obs=15);
 var e401k inc age ;
run;

Click here to view the printed log file in pdf.


Road map

  • Data Input
  • Data Manipulation
  • Some useful PROC steps
  • Merging and subsetting a dataset
  • Compute descriptive statistics
  • Compute test of differences
  • Ordinary Least Squares
  • Probit/Logit Regression
  • DO loops
  • WHILE loops
  • NESTED loops

Previous
Next