0% found this document useful (0 votes)
26 views24 pages

B1 Exercise Chapter 4

This document contains examples of SAS code for analyzing different datasets. It includes code for printing data, sorting data, filtering data by conditions, and summarizing numeric fields. The examples become more advanced through different levels and cover topics like libnames, WHERE clauses, BY variables and more.
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)
26 views24 pages

B1 Exercise Chapter 4

This document contains examples of SAS code for analyzing different datasets. It includes code for printing data, sorting data, filtering data by conditions, and summarizing numeric fields. The examples become more advanced through different levels and cover topics like libnames, WHERE clauses, BY variables and more.
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/ 24

EXERCISE CHAPTER 4.

LEVEL 1

libname orion " C:\Users\NIsaHumaira\OneDrive\Desktop\ICT


IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc print data=orion.order_fact;
sum Total_Retail_Price;
where Total_Retail_Price >500;
run;
c)the obs column has color

d) libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT


IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc print data=orion.order_fact noobs;
sum Total_Retail_Price;
where Total_Retail_Price >500;
run;
Can verify the number of observation by looking at log window

e) proc print data=orion.order_fact noobs ;


id Customer_ID;
where Total_Retail_Price >500;
run;

the customer id column has colour


f) libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc print data=orion.order_fact noobs;
sum Total_Retail_Price;
where Total_Retail_Price >500;
id Customer_ID;
var Customer_ID Order_ID Order_Type Quantity Total_Retail_Price;
run;

the customer id appear twice


g) libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc print data=orion.order_fact noobs;
sum Total_Retail_Price;
where Total_Retail_Price >500;
id Customer_ID;
var Order_ID Order_Type Quantity Total_Retail_Price;

run;
LEVEL 2
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc print data= orion.customer_dim noobs;
where Customer_Age between 30 and 40;
id Customer_ID;
var Customer_ID Customer_Name Customer_Age Customer_Type;
run;
CHALLENGE

EXERCISE 4.2

LEVEL 1
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc sort data=orion.sales
out=work.sales;
by Country Gender;
run;

proc print data=work.sales;


by Gender;
run;
proc sort data=orion.employee_payroll
out=work.sort_salary2;
by employee_gender descending salary;
run;
proc print data=work.sort_salary2;
by employee_gender;
run;
LEVEL 2
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc sort data=orion.employee_payroll
out=work.sort_sal;
by employee_gender descending salary;
run;
proc print data=work.sort_sal noobs;
where Employee_Term_Date=. ;
where same and salary>65000;
by employee_gender;
sum salary;
var employee_id salary marital_status;

run;
CHALLENGE
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc sort data=orion.orders
out=work.orders;
by customer_id;
run;
proc print data=work.orders;
by customer_id;

run;
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc sort data=orion.orders
out=work.orders
nodupkey dupout=work.duplicates;
by customer_id;
run;
proc print data=work.orders;
by customer_id;

run;
EXERCISE 4.3

LEVEL 1
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
proc sort data=orion.orders
out=work.orders
nodupkey dupout=work.duplicates;
by customer_id;
run;
proc print data=work.orders;
by customer_id;

run;
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
title1 'Australian Sales Employees';
title2 'Senior Sales Representatives';
footnote1 'Job_Tittle:Sales Rep.IV';
proc print data=orion.sales ;
var Employee_Id First_Name Last_Name Gender Salary;
where Country='AU' and Job_Title contains 'Rep. IV';
run;
title;
footnote;
title 'Entry-level Sales Representatives';
footnote 'Job_Title: Sales Rep. I';

proc print data=orion.sales noobs split ='*';


where Country='US' and Job_Title='Sales Rep. I';
var Employee_ID First_Name Last_Name Gender Salary;
label Employee_ID= 'Employee*ID'
First_Name ='First*Name'
Last_Name ='Last*Name'
Salary='Annual*Salary';

run;

title;

footnote;
LEVEL 2
libname orion "C:\Users\NIsaHumaira\OneDrive\Desktop\ICT
IV\DEGREE(4)\STA610\P1 2017 Data\P1 2017 Data";
title'US Employees by State';

proc sort data=orion.employee_addresses


out=work.employee_addresses ;
by state city employee_name ;
where state ne ' ';
run;
proc print data=work.employee_addresses split=' ' noobs ;
var employee_id employee_name city postal_code;
label employee_id='Employee ID'
employee_name='Name'
postal_code='Zip Code';
by state;

run;
title;
footnote;

You might also like