100% found this document useful (2 votes)
438 views10 pages

Assignment 2

This document describes an assignment involving joining and manipulating data from multiple SAS tables. It involves 5 tasks: 1) joining two tables and adding columns, 2) creating a calculated column using a function, 3) calculating years employed, 4) recoding country codes to names, and 5) recoding salary ranges. For each task, the document provides detailed instructions on the steps to complete, including creating output tables and SAS programs to perform the necessary data transformations and calculations. Screenshots and descriptions of the output are required. All SAS code must be included in a Word document and submitted along with written responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
438 views10 pages

Assignment 2

This document describes an assignment involving joining and manipulating data from multiple SAS tables. It involves 5 tasks: 1) joining two tables and adding columns, 2) creating a calculated column using a function, 3) calculating years employed, 4) recoding country codes to names, and 5) recoding salary ranges. For each task, the document provides detailed instructions on the steps to complete, including creating output tables and SAS programs to perform the necessary data transformations and calculations. Screenshots and descriptions of the output are required. All SAS code must be included in a Word document and submitted along with written responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

MGMT635 Assignment 2 (20 points)

1. Joining Data from Two Tables (5 points)


Use the New Query Builder to create a new table whose data results from a join of two tables. Create
a new column.
a. Use the New Query Builder to join employee_payroll and employee_addresses to create a table
named payroll_location.
b. Make sure that the join between the two tables is on the Employee_ID column.
c. Include the following columns on the Select Data tab: Employee_ID, Employee_Name,
Employee_Gender, Birth_Date, Salary, Street_Number, Street_Name, City, State,
Employee_Term_Date, and Country.
d. Click on Properties tab. Set the output location to MGMT635 and output name to be
payroll_location.
e. Run the new query. Provide the screenshots of the results and use complete sentences to describe
the attributes of payroll_location data set.

Payroll_location data set has 424 rows and 11 columns.


f. Write a SAS program for parts g through k below. Name the output file payroll_location_1.
g. Format the Salary column with a dollar sign, comma, and two decimal places.
h. Create a new column named Bonus that represents 1.5% of the Salary column. Format the values
with a dollar sign, comma, and two decimal places.
i. Create New_Salary, which is the current salary plus an additional 2% raise. Format the values
with a dollar sign, comma, and two decimal places.
j. Include only active employees in the output table. In other words, include only employees who
have a missing value for Employee_Term_Date.
k. Insert drop employee_term_date; directly before the RUN statement.
l. Run the code and view the results. Save the program in the SAS Code folder as Location.sas.
Provide the screenshots of the results and use complete sentences to describe the attributes of
payroll_location_1 data set.

Payroll_location_1 data set has 308 rows and 12 columns.

2. Creating a Calculated Column Using a Function (3 points)


3

Create a table from the employee_donations table with a new column that indicates the total
contributions from each employee.
a. Open the employee_donations SAS data set.
b. Write a SAS program to create a table named mgmt635.donations.
c. Create a new column named Total_Donations, which totals the values of the four quarterly
donations. Format the new column to display dollar signs, commas, and two decimal places.
 Use a function to calculate the total, thereby ignore any missing values that might be in
the input columns.
d. Include the Employee_ID, Recipients, Paid_By, and Total_Donations columns in the new
table.
e. Run the program. Save the program in the SAS Code folder as Donations.sas.
Provide the screenshot of mgmt635.donations table.
3. Creating a Program to Calculate the Number of Years Employed (4 points)
Write a SAS program to create a table named years_at_work in the MGMT635 folder that includes
active employees (those with no termination date) and the number of years that each has been
employed until December 10, 2020.
a. Use the Employee_Payroll table as the input table. Include Employee_ID and
Employee_Hire_Date. Include only employees without a termination date.
b. Create a new column named Years_Employed that calculates the number of years that each
employee worked at Orion Star, based on the hire date and today's date. Apply a format that
displays the values rounded to one decimal place.
Hint: The function YRDIF(start-date, end-date, ‘actual’) computes the years. The end-date is a
date constant '10Dec2020'd
The format is 4.1.
c. Run the program and verify the results. Save the program to the SAS Code folder as
Howlong.sas. Provide the screenshot of the years_at_work table and use complete
sentences to describe the attributes of this table.

Years_at_work data set has 308 rows and 3 columns.


5

d. Use the Characterize Data task to investigate the distribution of Years_Employed in the
years_at_work table. Provide the screenshot of the results, i.e. descriptive statistics and
distribution of Years Employed. Write a few lines about the distribution of Years Employed.

Years _employed data from years_at_work data set has a mean of 28.54 with a standard
deviation of 11.92. The extreme values have the highest percentages. The data looks like an
inverse bell curve.

* For additional information on YRDIF function, please visit the webpage at


http://documentation.sas.com/?
docsetId=ds2ref&docsetTarget=n18y49sva4majan124os3wch827a.htm&docsetVersion=3.1&locale=e
n
4. Creating a New Column by Recoding Distinct Values (4 points)
The Country column in the employee_addresses table includes country codes, such as US
and AU. Write SAS program that includes a new column, named Country_Name, that recodes the
values US and AU to the full country name. [Hints: 1) Pay attention to the length of Country_Name
column. 2) Use if upcase(Country) = “US” then… ; else if … then; else…; statement. 3) Pay attention
to the issue of letter case and missing values. You could use upcase(Country) to convert the values of
Country into uppercase strings. If Country information is missing for an observation, you could let
Country_Name = “Missing” or Country_Name = “”]
a. Create a table named mgmt635.country_name. Name the SAS program Country_name.sas and
store in the SAS Code folder.
b. Provide a screenshot of table mgmt635.country_name.
7

5. Creating a New Column by Recoding Ranges of Values (4 points)


Write a SAS program to create a new column that groups salary values into four categories. Name the
new column Salary_Range. Recall that Salary is in mgmt635.employee_payroll.
a. Create a table named mgmt635.Salary_Range.
b. Create a new column named Salary_Range based on the values in the Salary column.

0 – 24999.99 Below $25K

25000 – 49999.99 $25K to $50K

50000 – 99999.99 $50K to $100K

100000 and above Over $100K

c. Format Employee_Hire_Date with the DDMMYY10. format so that dates appear as 20/10/2008.
d. Include only the Employee_ID, Salary, Employee_Hire_Date, and Salary_Range columns.
e. Run the program. Save the program in the SAS Code folder as SalaryRange.sas. Provide a
screenshot of table mgmt635.Salary_Range.
Deliverables:
Step 1: Include all your answers to problems 1 to 5 in a word document and turn-in the word document via Learn.
Please also insert the SAS codes you wrote, i.e. codes in Location.sas, Donations.sas, Howlong.sas,
Country_name.sas and SalaryRange.sas, into the same word document.
SAS Code
Location.sas
data payroll_location_1;
set mgmt635.payroll_location;
format salary dollarx10.2;
Bonus = salary * 0.02;
9

format bonus dollarx10.2;


New_Salary = salary * 1.02;
format new_salary dollarx10.2;
if employee_term_date = .;
drop employee_term_date;
run;
Donations.sas
data mgmt635.donations;
set mgmt635.employee_donations;
Total_Donations = sum(qtr1, qtr2, qtr3, qtr4);
format total_donations dollarx10.2;
keep employee_id recipients paid_by total_donations;
run;
Howlong.sas
data mgmt635.years_at_work;
set mgmt635.employee_payroll;
where employee_term_date is missing;
Years_Employed = YRDIF(employee_hire_date, '10Dec2020'd, 'actual');
format years_employed 4.1;
keep employee_id employee_hire_date years_employed;
run;
Country_name.sas
data mgmt635.country_name;
set mgmt635.employee_addresses;
length Country_Name $ 20;
if upcase(Country) = "US" then Country_Name = "United States";
else if upcase(country) = "AU" then Country_Name = "Australia";
else Country_Name = "Missing";
run;
SalaryRange.sas
data mgmt635.salary_range;
set mgmt635.employee_payroll;
length Salary_Range $ 20;
if salary <= 24999.99 then salary_range = "Below $25K";
else if salary >= 25000.00 and salary <= 49999.99
then salary_range = "$25K to $50K";
else if salary >= 50000.00 and salary <= 99999.99
then salary_range = "$50K to $100K";
else salary_range = "Over $100K";
format employee_hire_date DDMMYY10.;
keep employee_id salary employee_hire_date salary_range;
run;
Step 2: Use the information in the Word document to take Assignment 2 quiz on Learn.
*Assignment 2 quiz score will be counted as your overall score for assignment 2. Assignment 2 quiz score could be
reduced by up to 5 points if a student does not submit the Word document showing answers to problems 1 to 5. The
instructor will randomly check the Word documents you submitted through Assignment 2 upload link on Learn and
make the adjustment.

You might also like