0% found this document useful (0 votes)
47 views19 pages

B1 Exercise Chapter 6

The document contains SAS code for multiple exercises and challenges. It creates several datasets from source datasets, applies filters, derives new variables, assigns formats and labels, and prints outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views19 pages

B1 Exercise Chapter 6

The document contains SAS code for multiple exercises and challenges. It creates several datasets from source datasets, applies filters, derives new variables, assigns formats and labels, and prints outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

EXERCISE CHAPTER 6.

LEVEL 1

a) Costumer_gender
F, M
data work.youngadult;
set orion.customer_dim;
Discount = 0.25;
run;

proc print data=work.youngadult noobs;


id customer_id;
where customer_gender='F' and customer_age > 18 and customer_age < 36
and customer_group contains 'Gold';
var customer_name customer_age customer_gender customer_group Discount;
run;
LEVEL 2
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";

data work.assistant;
set orion.staff;
where job_title contains 'Assistant' and salary < 26000;
increase = salary * 0.10;
new_salary = salary + increase;
run;

proc print data=work.assistant noobs;


id employee_id;
var job_title salary increase new_salary;
format salary new_salary dollar10.2 increase dollar9.2;
run;
CHALLENGE
libname orion"C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
data work.tony;
set orion.customer_dim;
where Customer_FirstName =* 'Tony';
run;
proc print data =work.tony split=' ';
var Customer_FirstName Customer_LastName;
label Customer_FirstName='Customer_ FirstName'
Customer_LastName='Customer_ LastName';
EXERCISE 6.2

LEVEL 1

data work.increase;
set orion.staff;
Increase=Salary*0.10;
NewSalary=Salary+Increase;
where emp_hire_date >= '01Jul2010'd ;
if Increase >3000;
keep employee_id emp_hire_date Salary Increase NewSalary;
label emp_hire_date ='Hire Date'
employee_id='Employee ID'
NewSalary='New Annual Salary'
Salary='Employee Annual Salary';
format emp_hire_date date9.
employee_id 12.
Increase comma5.
NewSalary Salary dollar10.2;
run;
proc contents data=work.increase;
run;

In the SAS program you provided, some variables in the work.subset1 dataset have labels and formats
that were not explicitly defined in the program. In SAS, labels and formats can be inherited from the
input dataset or from a previously defined format or label.

When a SAS dataset is created using a SET statement, the dataset inherits the variable attributes
(including labels and formats) from the input dataset. In this case, the work.subset1 dataset inherits
the labels and formats from the orion.sales dataset.
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
data work.increase;
set orion.staff;
Increase=Salary*0.10;
NewSalary=Salary+Increase;
where emp_hire_date >= '01Jul2010'd ;
if Increase >3000;
keep employee_id emp_hire_date Salary Increase NewSalary;
label emp_hire_date ='Hire Date'
employee_id='Employee ID'
NewSalary='New Annual Salary'
Salary='Employee Annual Salary';
format emp_hire_date date9.
employee_id 12.
Increase comma5.
NewSalary Salary dollar10.2;
run;
proc contents data=work.increase;
run;
proc print data=work.increase split=' ';
run;
LEVEL 2
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
data work.delays;
set orion.orders;
order_month=month(order_date);
where delivery_date - order_date > 4;
if employee_id=99999999 and order_month=8;
keep employee_id customer_id order_date delivery_date order_month;
label order_date ='Date Ordered'
delivery_date='Date Delivered'
order_month='Month Ordered';
format order_date delivery_date mmddyy10.;

run;

proc contents data=work.delays;


run;
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
data work.delays;
set orion.orders;
order_month=month(order_date);
where delivery_date - order_date > 4;
if employee_id=99999999 and order_month=8;
keep employee_id customer_id order_date delivery_date order_month;
label order_date ='Date Ordered'
delivery_date='Date Delivered'
order_month='Month Ordered';
format order_date delivery_date mmddyy10.;

run;
proc contents data=work.delays;
run;

proc print data=work.delays;


run;
CHALL ENGE
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
data work.bigdonations;
set orion.employee_donations;
Total = sum(Qtr1,Qtr2,Qtr3,Qtr4);
NumQtrs = n(Qtr1,Qtr2,Qtr3,Qtr4);
drop recipients paid_by;
if (Total < 50 or NumQtrs ne 4) then delete;
label Qtr1='First Quarter' Qtr2='Second Quarter' Qtr3='Third Quarter'
Qtr4='Forth Quarter';
run;
proc contents data=work.bigdonations;
run;
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";data work.bigdonations;
set orion.employee_donations;
Total = sum(Qtr1,Qtr2,Qtr3,Qtr4);
NumQtrs = n(Qtr1,Qtr2,Qtr3,Qtr4);
drop recipients paid_by;
if (Total < 50 or NumQtrs ne 4) then delete;
label Qtr1='First Quarter' Qtr2='Second Quarter' Qtr3='Third Quarter'
Qtr4='Forth Quarter';
run;

proc print data=work.bigdonations label noobs;


run;

You might also like