Create Temporary Dataset in SAS

Hey everyone

Now that we have SAS University Edition installed in our laptops/pcs, lets do a really simple exercise!

As the title of the blog post suggests, the exercise is to create a temporary dataset in SAS. For this we will write a SAS Program.

SAS Program contains of SAS Statements. Each SAS statement has two characteristics:

  1. Usually begins with a SAS keyword
  2. Ends with a semi colon(;)

This SAS program contains two steps: i. DATA step ii. PROC step.

  1. DATA step – basically creates or modifies SAS datasets.
  2. PROC (or procedure) step – pre-written rules that analyze and process data in a SAS dataset and then produce a report.

Most SAS programs contain either of these two steps or a combination of both these steps.

Program_1 : If we want to construct a dataset that represents only one object, say a machine, we will need only one observation.

data machine; 
ram = 6;
disk = 650;
run; 
proc print data=machine; 
run;

In the above program :

i. There are six SAS statements.

ii. DATA step –  creates a new dataset called machine.

iii. PROC step – prints/displays that dataset in the results/output window.

There is much more to DATA step and PROC step than the function performed in the above program.

Now select the whole program and click on Run optionsas7 in the toolbar or press F3.

If everything is correct, you will see the dataset printed in your results window. Like this: machine_result_SAS

 

Program_2: In statistics, we will mostly deal with datasets that are larger than one observation. Let’s modify the above program to make a larger dataset.

data machine;
input ram disk price;
cards;
6 650 1000
5 650 950
3 320 500
4 560 890
5 560 910
6 480 860
;
run;
proc print data= machine;
run;

In the above program:

i. There are seven SAS statements;

ii. This time we used DATA step to modify the machine dataset.

iii. The INPUT statement defines the variables to be read in each line of data.

iv. The CARDS statement indicates to SAS that DATA step statements are completed and the next line contains real data.

v. Notice that the lines of data do not end in a semicolon.

Note : The CARDS statement and DATALINES statement are interchangeable.

If everything is correct, you will see the dataset printed in your results window. Like this:SAS_machine

 

Where did SAS store this dataset?

In the explorer tab, click on Libraries > WORK > MACHINE(double click). If the library name is not specified, SAS stores the new datasets in WORK. This is how SAS stored machine dataset:

Work_sas_dataset

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s