173.COMPREHENSIVE ANALYSIS OF THE RICEBAG DATASET UTILIZING SAS PROCEDURES: PROC CONTENTS | PROC PRINT | PROC SQL | PROC MEANS | PROC REPORT | PROC SGPLOT | PROC SGPIE | PROC EXPORT | MACROS
- Get link
- X
- Other Apps
COMPREHENSIVE ANALYSIS OF THE RICEBAG DATASET UTILIZING SAS PROCEDURES: PROC CONTENTS | PROC PRINT | PROC SQL | PROC MEANS | PROC REPORT | PROC SGPLOT | PROC SGPIE | PROC EXPORT | MACROS
/*Creating a unique dataset named ricebag*/
/*Creating the ricebag Dataset*/
data ricebag;
length BagID $10 RiceType $20 StorageLocation $20;
input BagID $ RiceType $ Weight Price StorageLocation $;
datalines;
RB001 Basmati 25 1200 Hyderabad
RB002 SonaMasuri 30 950 Vijayawada
RB003 Basmati 20 1000 Hyderabad
RB004 Jasmine 15 1100 Chennai
RB005 SonaMasuri 25 900 Vijayawada
RB006 Basmati 30 1300 Hyderabad
RB007 Jasmine 20 1150 Chennai
RB008 SonaMasuri 15 850 Vijayawada
RB009 Basmati 25 1250 Hyderabad
RB010 Jasmine 30 1200 Chennai
;
run;
proc print;run;
Output:
Obs | BagID | RiceType | StorageLocation | Weight | Price |
---|---|---|---|---|---|
1 | RB001 | Basmati | Hyderabad | 25 | 1200 |
2 | RB002 | SonaMasuri | Vijayawada | 30 | 950 |
3 | RB003 | Basmati | Hyderabad | 20 | 1000 |
4 | RB004 | Jasmine | Chennai | 15 | 1100 |
5 | RB005 | SonaMasuri | Vijayawada | 25 | 900 |
6 | RB006 | Basmati | Hyderabad | 30 | 1300 |
7 | RB007 | Jasmine | Chennai | 20 | 1150 |
8 | RB008 | SonaMasuri | Vijayawada | 15 | 850 |
9 | RB009 | Basmati | Hyderabad | 25 | 1250 |
10 | RB010 | Jasmine | Chennai | 30 | 1200 |
/*Exploring the Dataset*/
proc contents data=ricebag;
run;
Output:
Data Set Name | WORK.RICEBAG | Observations | 10 |
---|---|---|---|
Member Type | DATA | Variables | 5 |
Engine | V9 | Indexes | 0 |
Created | 14/09/2015 00:03:14 | Observation Length | 72 |
Last Modified | 14/09/2015 00:03:14 | Deleted Observations | 0 |
Protection | Compressed | NO | |
Data Set Type | Sorted | NO | |
Label | |||
Data Representation | WINDOWS_64 | ||
Encoding | wlatin1 Western (Windows) |
Engine/Host Dependent Information | |
---|---|
Data Set Page Size | 65536 |
Number of Data Set Pages | 1 |
First Data Page | 1 |
Max Obs per Page | 908 |
Obs in First Data Page | 10 |
Number of Data Set Repairs | 0 |
ExtendObsCounter | YES |
Filename | C:\Users\Lenovo\AppData\Local\Temp\SAS Temporary Files\_TD9512_DESKTOP-QFAA4KV_\ricebag.sas7bdat |
Release Created | 9.0401M2 |
Host Created | X64_8HOME |
Alphabetic List of Variables and Attributes | |||
---|---|---|---|
# | Variable | Type | Len |
1 | BagID | Char | 10 |
5 | Price | Num | 8 |
2 | RiceType | Char | 20 |
3 | StorageLocation | Char | 20 |
4 | Weight | Num | 8 |
proc print data=ricebag;
run;
Output:
Obs | BagID | RiceType | StorageLocation | Weight | Price |
---|---|---|---|---|---|
1 | RB001 | Basmati | Hyderabad | 25 | 1200 |
2 | RB002 | SonaMasuri | Vijayawada | 30 | 950 |
3 | RB003 | Basmati | Hyderabad | 20 | 1000 |
4 | RB004 | Jasmine | Chennai | 15 | 1100 |
5 | RB005 | SonaMasuri | Vijayawada | 25 | 900 |
6 | RB006 | Basmati | Hyderabad | 30 | 1300 |
7 | RB007 | Jasmine | Chennai | 20 | 1150 |
8 | RB008 | SonaMasuri | Vijayawada | 15 | 850 |
9 | RB009 | Basmati | Hyderabad | 25 | 1250 |
10 | RB010 | Jasmine | Chennai | 30 | 1200 |
/*Calculating Average Price by Rice Type*/
proc sql;
select RiceType, avg(Price) as AvgPrice
from ricebag
group by RiceType;
quit;
Output:
RiceType | AvgPrice |
---|---|
Basmati | 1187.5 |
Jasmine | 1150 |
SonaMasuri | 900 |
/*Identifying the Most Expensive Rice Bag*/
proc sql;
select *
from ricebag
where Price = (select max(Price) from ricebag);
quit;
Output:
BagID | RiceType | StorageLocation | Weight | Price |
---|---|---|---|---|
RB006 | Basmati | Hyderabad | 30 | 1300 |
/*Counting Bags per Storage Location*/
proc sql;
select StorageLocation, count(*) as BagCount
from ricebag
group by StorageLocation;
quit;
Output:
StorageLocation | BagCount |
---|---|
Chennai | 3 |
Hyderabad | 4 |
Vijayawada | 3 |
/*Calculating Price per Kilogram*/
data ricebag;
set ricebag;
PricePerKg = Price / Weight;
run;
proc print;run;
Output:
Obs | BagID | RiceType | StorageLocation | Weight | Price | PricePerKg |
---|---|---|---|---|---|---|
1 | RB001 | Basmati | Hyderabad | 25 | 1200 | 48.0000 |
2 | RB002 | SonaMasuri | Vijayawada | 30 | 950 | 31.6667 |
3 | RB003 | Basmati | Hyderabad | 20 | 1000 | 50.0000 |
4 | RB004 | Jasmine | Chennai | 15 | 1100 | 73.3333 |
5 | RB005 | SonaMasuri | Vijayawada | 25 | 900 | 36.0000 |
6 | RB006 | Basmati | Hyderabad | 30 | 1300 | 43.3333 |
7 | RB007 | Jasmine | Chennai | 20 | 1150 | 57.5000 |
8 | RB008 | SonaMasuri | Vijayawada | 15 | 850 | 56.6667 |
9 | RB009 | Basmati | Hyderabad | 25 | 1250 | 50.0000 |
10 | RB010 | Jasmine | Chennai | 30 | 1200 | 40.0000 |
/*Categorizing Rice Bags Based on Weight*/
data ricebag;
retain BagID RiceType StorageLocation Weight Price PricePerKg ;
length WeightCategory $15.;
set ricebag;
if Weight < 20 then WeightCategory = 'Light';
else if Weight <= 25 then WeightCategory = 'Medium';
else WeightCategory = 'Heavy';
run;
proc print;run;
Output:
Obs | BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|---|
1 | RB001 | Basmati | Hyderabad | 25 | 1200 | 48.0000 | Medium |
2 | RB002 | SonaMasuri | Vijayawada | 30 | 950 | 31.6667 | Heavy |
3 | RB003 | Basmati | Hyderabad | 20 | 1000 | 50.0000 | Medium |
4 | RB004 | Jasmine | Chennai | 15 | 1100 | 73.3333 | Light |
5 | RB005 | SonaMasuri | Vijayawada | 25 | 900 | 36.0000 | Medium |
6 | RB006 | Basmati | Hyderabad | 30 | 1300 | 43.3333 | Heavy |
7 | RB007 | Jasmine | Chennai | 20 | 1150 | 57.5000 | Medium |
8 | RB008 | SonaMasuri | Vijayawada | 15 | 850 | 56.6667 | Light |
9 | RB009 | Basmati | Hyderabad | 25 | 1250 | 50.0000 | Medium |
10 | RB010 | Jasmine | Chennai | 30 | 1200 | 40.0000 | Heavy |
/*Utilizing Macros for Dynamic Analysis*/
%macro analyze_rice(rice_type);
proc sql;
select *
from ricebag
where RiceType = "&rice_type";
quit;
proc means data=ricebag noprint;
where RiceType = "&rice_type";
var Price Weight;
output out=stats_&rice_type mean=AvgPrice AvgWeight;
run;
proc print data=stats_&rice_type;
title "Statistics for &rice_type Rice Bags";
run;
%mend analyze_rice;
%analyze_rice(Basmati);
Output:
BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|
RB001 | Basmati | Hyderabad | 25 | 1200 | 48 | Medium |
RB003 | Basmati | Hyderabad | 20 | 1000 | 50 | Medium |
RB006 | Basmati | Hyderabad | 30 | 1300 | 43.33333 | Heavy |
RB009 | Basmati | Hyderabad | 25 | 1250 | 50 | Medium |
%analyze_rice(SonaMasuri);
Output:
BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|
RB002 | SonaMasuri | Vijayawada | 30 | 950 | 31.66667 | Heavy |
RB005 | SonaMasuri | Vijayawada | 25 | 900 | 36 | Medium |
RB008 | SonaMasuri | Vijayawada | 15 | 850 | 56.66667 | Light |
%analyze_rice(Jasmine);
Output:
BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|
RB004 | Jasmine | Chennai | 15 | 1100 | 73.33333 | Light |
RB007 | Jasmine | Chennai | 20 | 1150 | 57.5 | Medium |
RB010 | Jasmine | Chennai | 30 | 1200 | 40 | Heavy |
Statistics for Jasmine Rice Bags |
Obs | _TYPE_ | _FREQ_ | AvgPrice | AvgWeight |
---|---|---|---|---|
1 | 0 | 3 | 1150 | 21.6667 |
/*Creating Separate Datasets for Each Rice Type*/
proc sql noprint;
select distinct RiceType into :types separated by ' '
from ricebag;
quit;
%macro split_datasets;
%let count = %sysfunc(countw(&types));
%do i = 1 %to &count;
%let type = %scan(&types, &i);
data &type;
set ricebag;
where RiceType = "&type";
run;
proc print;run;
%end;
%mend split_datasets;
%split_datasets;
Output:
Obs | BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|---|
1 | RB001 | Basmati | Hyderabad | 25 | 1200 | 48.0000 | Medium |
2 | RB003 | Basmati | Hyderabad | 20 | 1000 | 50.0000 | Medium |
3 | RB006 | Basmati | Hyderabad | 30 | 1300 | 43.3333 | Heavy |
4 | RB009 | Basmati | Hyderabad | 25 | 1250 | 50.0000 | Medium |
Obs | BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|---|
1 | RB004 | Jasmine | Chennai | 15 | 1100 | 73.3333 | Light |
2 | RB007 | Jasmine | Chennai | 20 | 1150 | 57.5000 | Medium |
3 | RB010 | Jasmine | Chennai | 30 | 1200 | 40.0000 | Heavy |
Obs | BagID | RiceType | StorageLocation | Weight | Price | PricePerKg | WeightCategory |
---|---|---|---|---|---|---|---|
1 | RB002 | SonaMasuri | Vijayawada | 30 | 950 | 31.6667 | Heavy |
2 | RB005 | SonaMasuri | Vijayawada | 25 | 900 | 36.0000 | Medium |
3 | RB008 | SonaMasuri | Vijayawada | 15 | 850 | 56.6667 | Light |
/*Bar Chart of Average Price by Rice Type*/
proc sgplot data=ricebag;
vbar RiceType / response=Price stat=mean;
title "Average Price by Rice Type";
run;
Log:
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 2.34 seconds
cpu time 0.57 seconds
NOTE: Listing image output written to SGPlot1.png.
NOTE: There were 10 observations read from the data set WORK.RICEBAG.
/*Pie Chart of Rice Bags by Storage Location*/
proc gchart data=ricebag;
pie StorageLocation / value=inside percent=inside slice=outside;
title "Distribution of Rice Bags by Storage Location";
run;
quit;
Log:
NOTE: There were 10 observations read from the data set WORK.RICEBAG.
NOTE: PROCEDURE GCHART used (Total process time):
real time 2.45 seconds
cpu time 0.67 seconds
/*Generating Reports*/
proc report data=ricebag nowd;
column RiceType WeightCategory PricePerKg;
define RiceType / group;
define WeightCategory / group;
define PricePerKg / mean;
title "Summary Report of Rice Bags";
run;
Output:
Summary Report of Rice
Bags |
RiceType | WeightCategory | PricePerKg |
---|---|---|
Basmati | Heavy | 43.333333 |
Medium | 49.333333 | |
Jasmine | Heavy | 40 |
Light | 73.333333 | |
Medium | 57.5 | |
SonaMasuri | Heavy | 31.666667 |
Light | 56.666667 | |
Medium | 36 |
/*Exporting Data*/
proc export data=ricebag
outfile="C:\Users\YourUsername\Documents\ricebag.csv"
dbms=csv
replace;
run;
Find A Mistake and Comment It:
proc sgplot data=ricebag;
pie StorageLocation / response=BagID stat=count;
title "Distribution of Rice Bags by Storage Location";
run;
- Get link
- X
- Other Apps
Comments
Post a Comment