Create data set and read, write, and manipulate data

Assignment Help Other Subject
Reference no: EM133147815 , Length: word count:800

ITECH3101 Business Analytics and Decision Support - Federation University

Exercise - Introduction of SAS programming

Project 1: Knowing DATA steps and PROC steps

SAS programs consist of DATA steps and PROC steps.

In DATA steps, you can create data set and read, write, and manipulate data. Then DATA steps pass the data to a PROC step for processing. DATA steps begin with keyword DATA and usually end with a RUN statement.

In PROC( short for procedure) steps, you can use built-in procedures to analyze data and complete tasks such as writing reports, summarizing data or creating graphical output. PROC steps begin with the word PROC and end with either a RUN or QUIT statement(or both).

Task: Write your first SAS program.

Step 1. Get into your SAS Studio, and select CODE tap Step 2. Write code and run program.
Step 3. Look at LOG and RESULT. Step 4 Store your program

Step 1. Get into your SAS Studio, and select CODE tap.

When you open SAS Studio, make sure that you have CODE highlighted. The CODE window is a place where you write your SAS program.

Step 2. Write code and run program.

(1) You may first write the comment with an asterisk and end it with a semicolon. The comment will introduce the purpose of the program.

(2) Select Preferences to Enable auto complete function

When you type some keywords in the CODE window, SAS Studio shows you syntax and options for helping program. You can select or deselect Autocomplete function.

(3) Write code and run the program

In this program:

Statement 2 names a data set called Convert.
Statement 3 tells the program where original data is located. To read and write data between SAS Studio session and your hard drive, you need to place your data in a specific location: \SASUniversityEdition\myfolders.

You can place \SASUniversityEdition\myfloders at location you selected. This location (\SASUniversityEdition\myfolders) is mapped to a shared folder called
/folders/myfolders in SAS Studio.
Statement 4 reads data from the celsius.txt file.
Statement 5 uses a formula to convert Celsius to Fahrenheit. Statement 6 ends DATA step.
Statement 8 lists the content of data set convert.
Statement 9 specifies which variables you want to include in report.

Step 3. Look at LOG and RESULT.
After running your program, you can have a look at the result of program.

The RESULTS window is place where SAS output appears. Click RESULTS tap:

The LOG window displays your program, any syntax errors in the program, information about data reading and writing and CPU time used, etc.


Step 4 Save your program

From CODE tab, select the icon for SAVE AS

SASUSER is a permanent SAS library that is created automatically for each user. This library should have been allocated to the shared folder:
\SASUniversityEdition\myfolders\sasuser.v94.

After selecting the Save As and expanding My folders, select assuser.v94 and enter program name, and then click on Save button.

Summary of storage of SAS data and program files

A SAS library is a location where SAS data sets and other types of SAS files are stored.

1) SASUSER is a permanent SAS library that is created automatically for each user.

2) WORK library is a temporary storage location for SAS data sets. It is the default library. If you create a SAS data set without specifying a library, SAS will put it in the WORK library, and then delete it when you end your session.

3) Create your new library

Click New Library tap to open new library window.

In the New library window, type the name of library. In Path field, click the Browse button to navigate to the folder or directory where you want your data sets to be stored.

Then click Ok and the library Week2 you just created will appear in Active Libraries window.

Project 2: Basic programming rules

Task: This project will focus primarily on basic programming rules of SAS, data step part of SAS and proc step part of SAS.

1. Basic Concepts and Rules

1) Each statement in SAS must end in a semicolon (;).
2) SAS variable names must be 32 characters or less, constructed of letters, digits and the underscore character.
3) SAS is not case sensitive, except inside of quoted strings
4) Data set names follow similar rules as variables, but they have a different name space
5) Missing values are handled consistently in SAS, and are represented by a period (.).
6) Names must start with a letter or an underscore ( _ ).
7) Data type. There are two data types: numerical and character.

2. SAS programs consist of two types of steps

1) DATA (data step):
• Begin with DATA statements
• Read external (or internal) data files to create SAS datasets
• Create new SAS datasets by submerging, merging, modifying, and updating existing SAS data sets.
• Create new variables
• Analyze, operate or display data
• Extract the information
• Generate reports or save files to hard disks

Please note that DATA steps execute line by line and observation by observation.

(1) Execute line by line

SAS executes line one of your DATA step before it executes line two, and line two before line three, and so on.

(2) Execute observation by observation

SAS takes the firs observation and runs it all the way through the DATA step
(line by line) before looping back to pick up the second observation. In this case, SAS sees only one observation at a time.

DATA steps execute line by line and observation by observation

2) PROC (procedure step):

PROC STEPS invoke and execute programs through a series of SAS statements. Usually a data set is used as input data.

(1) begin with PROC statements
(2) perform specific analysis or function such as produce summaries of the data
(3) produce results or report such as tables, plots and results of statistical analyses

SAS contains a vast number of procedure that has been developed over many years and by many teams of programmers.
All procedure steps begin with PROC. Overall procedure syntax:

PROC procname DATA=dataname; (specific part of program)
RUN;

Please note that always start by naming the relevant procedure and the data to be analyzed.

Project 3: Example of DATA steps and PROC steps

Task: Make data in SAS.

Step 1. Get into your SAS Studio, and select CODE tap Step 2. Write code and run program.
Step 3. Look at LOG and RESULT. Step 4 Store your program

Step 1. Get into your SAS Studio, and select New icon on the left-hand pane under the Server Files and Folders.

Step 2. Write code and run program.

After clicking Run tap, we get

Question 1

In DATA step in the above program, there are two names. Why is there only one row of data instead of two rows in OUTUT DATA tab?

The reason is that the code did not explicitly output the second set of variables so the second set of data is not written out and saved into the dataset.

Step 2. Add the second output before the run
After clicking Run tap, we get

Question 2

In OUTUT DATA tab, the second value of name should have been Steve, but it gets truncated to Stev. Why is the second value for the name variable truncated in OUTUT DATA tab?

The reason is that SAS implicitly declared name to be a character based on the First instance ( Mike) and it also implicitly declared the length of character variable based on the value it had information on (Mike). Therefore, the length was implicitly set to 4. In this case, Steve gets truncated to Stev.

Step 3. Use length data step statement

There is a dollar sign ($) after the variable name. It indicates that name is declared to be a character and its length is 5.

After clicking Run tap, we get

Step 3. Explicitly declare the types and lengths of variables

There is a better way to make data within SAS. For example, we can explicitly declare the types and lengths of variables. In addition, we can use INPUT and DATALINES or CARDS data step statements to read in multiple rows of data all at once.

After clicking Run tap, we get

• length statement explicitly declares the types and lengths of variable: name is a character variable and its length is 5. x and y are numeric variables and their length are 8.
• input statement tells SAS how to read raw data. In this case, this statement tells SAS to read three data values from a character variable name and 2 numeric variables x and y.
• datalines ( or cards) statement is used to read raw data directly in your SAS program and it must be the last statement in the DATA step.

Project 4: Making datasets using SQL type statements

1. We can use PROC SQL to make datasets within SAS. There are two basic ways to use SQL with SAS;
(1) embed complete SQL statements in the SQL procedure
(2) use WHERE statements or WHERE= data set option to select rows in SAS DATA and PROC steps

2. Basic form of SQL procedure is:

PROC SQL;
sql-statement;

The possible values for sql-statement in PROC SQL include CREATE, DELETE SELECT, UPDATE, etc, with a semicolon stuck on the end.

3. SQL does not contain structures like SAS DATA and PROCE steps and operations performed by most other SAS procedures don't exist in SQL.

4. In SQL, reports are written automatically whenever you use a SELECT statement.

5. PROC SQL can run interactively without a RUN statement.

Examples:

1) making a new dataset

In the above code, you make a new dataset named sqltry1 in work library with three variables and no observations or rows.

After clicking Run tap, we get

2) You can also use PROC SQL to create new datasets through querying a table that already exists within an existing SAS library.

After clicking RESULTS tap, we get

Project 5. Answering questions (Please do this at your home by using your own computer)

1. List five best practices of dashboard design

Project 6. Creating a Professional Report

Summarize the above experiments procedure, results, answering questions and screenshots (project 1, 2, 3, 4, 5) into one report. Your report is the assignment that is required to be submitted for evaluation on week 11. Create a report by following below steps.

You can add a chapter called Chapter 5 in your previous report.

1. Open your last week's report and find the end of last week's report.

2. Copy this week's related experimental results, your findings and Screenshots, and paste them at the end of last week's report.

3. Delete original Table of Content you created.

4. Select all content , align all text to both left and right margin

5. Use shortcut key approach, generate Chapter 5: Introduction of SAS programming

6. Then use shortcut key approach to generate proper sub-chapters for this week's lab work.

7. Insert Table of Contents to your report.

Attachment:- Introduction of SAS programming.rar

Reference no: EM133147815

Questions Cloud

League and tourism management questions : These are League and Tourism Management questions.
Conflict between israel and palestine on juraselm : Why is there a conflict between Israel and Palestine on Juraselm? What is the importance of Jerusalem for both sides?
How much is the depreciation for the year : An accounting change was made in 2024 to reflect these additional data. How much is the depreciation for the year 2022
Why do rapidly growing firms generally pay no dividends : Question - What are the two ways that firms can distribute cash to shareholders? Why do rapidly growing firms generally pay no dividends
Create data set and read, write, and manipulate data : Create data set and read, write, and manipulate data. Then DATA steps pass the data to a PROC step for processing. DATA steps begin with keyword DATA
Calculate the carrying amount of the plant : Calculate the carrying amount of the plant that should appear in Masai Berhad's statement of financial position as at 31 March 2022
List the decision-making errors : Read the article provided on decision-making errors and complete the activities:
What is the process of target costing : How would a manager use economic theory to determine profit-maximizing price for a service or product? What is the process of target costing
Leadership of a grocery store chain : Imagine that you lead a team that comprises the leadership of a grocery store chain. Using the supply and demand curve, explore a variety of actions you might t

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd