137.ANALYZING GLOBAL RENEWABLE ENERGY CONSUMPTION DATA USING SAS: DATA CREATION, MANAGEMENT, AND ADVANCED ANALYTICAL PROCEDURES FOR INSIGHTFUL ENERGY ANALYSIS
- Get link
- X
- Other Apps
ANALYZING GLOBAL RENEWABLE ENERGY CONSUMPTION DATA USING SAS: DATA CREATION, MANAGEMENT, AND ADVANCED ANALYTICAL PROCEDURES FOR INSIGHTFUL ENERGY ANALYSIS
/*Step 1: Creating the Dataset*/
/*We'll design a dataset named RenewableEnergy that encapsulates information about
different countries, their renewable energy consumption, the type of renewable energy,
and the year of record. Here's how you can create this dataset in SAS:*/
data RenewableEnergy;
input Country $ EnergyType $ ConsumptionMW Year;
datalines;
USA Solar 50000 2020
USA Wind 60000 2020
USA Hydro 80000 2020
Germany Solar 45000 2020
Germany Wind 55000 2020
Germany Hydro 70000 2020
India Solar 30000 2020
India Wind 35000 2020
India Hydro 50000 2020
China Solar 70000 2020
China Wind 80000 2020
China Hydro 90000 2020
Brazil Solar 20000 2020
Brazil Wind 25000 2020
Brazil Hydro 60000 2020
;
run;
proc print;run;
Output:
Obs | Country | EnergyType | ConsumptionMW | Year |
---|---|---|---|---|
1 | USA | Solar | 50000 | 2020 |
2 | USA | Wind | 60000 | 2020 |
3 | USA | Hydro | 80000 | 2020 |
4 | Germany | Solar | 45000 | 2020 |
5 | Germany | Wind | 55000 | 2020 |
6 | Germany | Hydro | 70000 | 2020 |
7 | India | Solar | 30000 | 2020 |
8 | India | Wind | 35000 | 2020 |
9 | India | Hydro | 50000 | 2020 |
10 | China | Solar | 70000 | 2020 |
11 | China | Wind | 80000 | 2020 |
12 | China | Hydro | 90000 | 2020 |
13 | Brazil | Solar | 20000 | 2020 |
14 | Brazil | Wind | 25000 | 2020 |
15 | Brazil | Hydro | 60000 | 2020 |
/*In this dataset:*/
/*Country: Name of the country.*/
/*EnergyType: Type of renewable energy (e.g., Solar, Wind, Hydro).*/
/*ConsumptionMW: Energy consumption in megawatts.*/
/*Year: The year of the recorded data.*/
/*Step 2: Exploring the Dataset with PROC CONTENTS*/
/*To understand the structure of the RenewableEnergy dataset, we can use the
PROC CONTENTS procedure:*/
proc contents data=RenewableEnergy;
run;
Output:
Alphabetic List of Variables and Attributes | |||
---|---|---|---|
# | Variable | Type | Len |
3 | ConsumptionMW | Num | 8 |
1 | Country | Char | 8 |
2 | EnergyType | Char | 8 |
4 | Year | Num | 8 |
/*This procedure provides detailed information about the dataset, including
variable names, types, and attributes.*/
/*Step 3: Sorting Data with PROC SORT*/
/*Before performing analyses, it's often beneficial to sort the data.
For instance, to sort the dataset by Country and EnergyType:*/
proc sort data=RenewableEnergy;
by Country EnergyType;
run;
proc print;run;
Output:
Obs | Country | EnergyType | ConsumptionMW | Year |
---|---|---|---|---|
1 | Brazil | Hydro | 60000 | 2020 |
2 | Brazil | Solar | 20000 | 2020 |
3 | Brazil | Wind | 25000 | 2020 |
4 | China | Hydro | 90000 | 2020 |
5 | China | Solar | 70000 | 2020 |
6 | China | Wind | 80000 | 2020 |
7 | Germany | Hydro | 70000 | 2020 |
8 | Germany | Solar | 45000 | 2020 |
9 | Germany | Wind | 55000 | 2020 |
10 | India | Hydro | 50000 | 2020 |
11 | India | Solar | 30000 | 2020 |
12 | India | Wind | 35000 | 2020 |
13 | USA | Hydro | 80000 | 2020 |
14 | USA | Solar | 50000 | 2020 |
15 | USA | Wind | 60000 | 2020 |
/*Step 4: Summarizing Data with PROC MEANS*/
/*To obtain descriptive statistics on energy consumption:*/
proc means data=RenewableEnergy mean median maxdec=2;
var ConsumptionMW;
class Country EnergyType;
run;
Output:
Analysis Variable : ConsumptionMW | ||||
---|---|---|---|---|
Country | EnergyType | N Obs | Mean | Median |
Brazil | Hydro | 1 | 60000.00 | 60000.00 |
Solar | 1 | 20000.00 | 20000.00 | |
Wind | 1 | 25000.00 | 25000.00 | |
China | Hydro | 1 | 90000.00 | 90000.00 |
Solar | 1 | 70000.00 | 70000.00 | |
Wind | 1 | 80000.00 | 80000.00 | |
Germany | Hydro | 1 | 70000.00 | 70000.00 |
Solar | 1 | 45000.00 | 45000.00 | |
Wind | 1 | 55000.00 | 55000.00 | |
India | Hydro | 1 | 50000.00 | 50000.00 |
Solar | 1 | 30000.00 | 30000.00 | |
Wind | 1 | 35000.00 | 35000.00 | |
USA | Hydro | 1 | 80000.00 | 80000.00 |
Solar | 1 | 50000.00 | 50000.00 | |
Wind | 1 | 60000.00 | 60000.00 |
/*This code calculates the mean and median energy consumption for each combination
of Country and EnergyType, displaying results with two decimal places.*/
/*Step 5: Generating Frequency Tables with PROC FREQ*/
/*To analyze the distribution of energy types across countries:*/
proc freq data=RenewableEnergy;
tables Country*EnergyType / norow nocol nopercent;
run;
Output:
|
|
/*This cross-tabulation shows the count of each energy type per country without
displaying row, column, or percentage values.*/
/*Step 6: Data Transformation with PROC TRANSPOSE*/
/*Suppose we want to restructure the dataset to have energy types as columns
for each country. We can achieve this using PROC TRANSPOSE:*/
proc transpose data=RenewableEnergy out=EnergyTransposed;
by Country Year;
id EnergyType;
var ConsumptionMW;
run;
proc print;run;
Obs | Country | Year | _NAME_ | Hydro | Solar | Wind |
---|---|---|---|---|---|---|
1 | Brazil | 2020 | ConsumptionMW | 60000 | 20000 | 25000 |
2 | China | 2020 | ConsumptionMW | 90000 | 70000 | 80000 |
3 | Germany | 2020 | ConsumptionMW | 70000 | 45000 | 55000 |
4 | India | 2020 | ConsumptionMW | 50000 | 30000 | 35000 |
5 | USA | 2020 | ConsumptionMW | 80000 | 50000 | 60000 |
/*This transposes the EnergyType values into separate columns, with their
corresponding ConsumptionMW values.*/
/*Step 7: Creating Custom Formats with PROC FORMAT*/
/*To enhance the readability of our reports, we can define custom formats.
For example, let's categorize the energy consumption levels:*/
proc format;
value ConsumptionFmt
low-<40000 = 'Low'
40000-<70000 = 'Medium'
70000-high = 'High';
run;
/*Applying this format in a report:*/
proc print data=RenewableEnergy;
var Country EnergyType ConsumptionMW;
format ConsumptionMW ConsumptionFmt.;
run;
Output:
Obs | Country | EnergyType | ConsumptionMW |
---|---|---|---|
1 | Brazil | Hydro | Medium |
2 | Brazil | Solar | Low |
3 | Brazil | Wind | Low |
4 | China | Hydro | High |
5 | China | Solar | High |
6 | China | Wind | High |
7 | Germany | Hydro | High |
8 | Germany | Solar | Medium |
9 | Germany | Wind | Medium |
10 | India | Hydro | Medium |
11 | India | Solar | Low |
12 | India | Wind | Low |
13 | USA | Hydro | High |
14 | USA | Solar | Medium |
15 | USA | Wind | Medium |
/*This will display the consumption levels as 'Low', 'Medium', or 'High'
based on the defined ranges.*/
/*Step 8: Appending Data with PROC APPEND*/
/*Imagine we have a new dataset, RenewableEnergy2021, containing data for the year 2021. We can append this data to our existing RenewableEnergy dataset:*/
proc append base=RenewableEnergy2021 data=RenewableEnergy;
run;proc print;run;
Output:
Obs | Country | EnergyType | ConsumptionMW | Year |
---|---|---|---|---|
1 | Brazil | Hydro | 60000 | 2020 |
2 | Brazil | Solar | 20000 | 2020 |
3 | Brazil | Wind | 25000 | 2020 |
4 | China | Hydro | 90000 | 2020 |
5 | China | Solar | 70000 | 2020 |
6 | China | Wind | 80000 | 2020 |
7 | Germany | Hydro | 70000 | 2020 |
8 | Germany | Solar | 45000 | 2020 |
9 | Germany | Wind | 55000 | 2020 |
10 | India | Hydro | 50000 | 2020 |
11 | India | Solar | 30000 | 2020 |
12 | India | Wind | 35000 | 2020 |
13 | USA | Hydro | 80000 | 2020 |
14 | USA | Solar | 50000 | 2020 |
15 | USA | Wind | 60000 | 2020 |
/*This procedure adds the observations from RenewableEnergy2021 to RenewableEnergy.*/
/*Step 9: Merging Datasets with DATA Step*/
/*If we have another dataset containing additional information,
such as CountryDetails with attributes like GDP and Population,
we can merge it with our RenewableEnergy dataset:*/
data EnergyWithDetails;
merge RenewableEnergy(in=a) RenewableEnergy2021(in=b);
by Country;
if a and b;
run;
Output:
Obs | Country | EnergyType | ConsumptionMW | Year |
---|---|---|---|---|
1 | Brazil | Hydro | 60000 | 2020 |
2 | Brazil | Solar | 20000 | 2020 |
3 | Brazil | Wind | 25000 | 2020 |
4 | China | Hydro | 90000 | 2020 |
5 | China | Solar | 70000 | 2020 |
6 | China | Wind | 80000 | 2020 |
7 | Germany | Hydro | 70000 | 2020 |
8 | Germany | Solar | 45000 | 2020 |
9 | Germany | Wind | 55000 | 2020 |
10 | India | Hydro | 50000 | 2020 |
11 | India | Solar | 30000 | 2020 |
12 | India | Wind | 35000 | 2020 |
13 | USA | Hydro | 80000 | 2020 |
14 | USA | Solar | 50000 | 2020 |
15 | USA | Wind | 60000 | 2020 |
/*This merges the datasets by Country, including only the records that exist in
both datasets.*/
/*Step 10: Renaming Variables with PROC DATASETS*/
/*To rename variables for clarity, we can use the PROC DATASETS procedure:*/
proc datasets library=work;
modify RenewableEnergy;
rename ConsumptionMW=EnergyConsumption_MW;
run;
quit;
Output Log:
Member File
# Name Type Size Last Modified
1 ENERGYTRANSPOSED DATA 131072 28/03/2025 09:06:09
2 ENERGYWITHDETAILS DATA 131072 28/03/2025 09:11:26
3 FORMATS CATALOG 17408 28/03/2025 09:07:01
4 RENEWABLEENERGY DATA 131072 28/03/2025 09:07:43
5 RENEWABLEENERGY2021 DATA 131072 28/03/2025 09:08:48
/*This changes the variable name from ConsumptionMW to EnergyConsumption_MW within the RenewableEnergy dataset.*/
/*Step 11: Deleting Datasets with PROC DATASETS*/
/*To remove datasets that are no longer needed:*/
proc datasets library=work;
delete RenewableEnergy2021;
run;
quit;
Output:
Directory | |
---|---|
Libref | WORK |
Engine | V9 |
Physical Name | C:\Users\Lenovo\AppData\Local\Temp\SAS Temporary Files\_TD9692_DESKTOP-QFAA4KV_ |
Filename | C:\Users\Lenovo\AppData\Local\Temp\SAS Temporary Files\_TD9692_DESKTOP-QFAA4KV_ |
# | Name | Member Type | File Size | Last Modified |
---|---|---|---|---|
1 | ENERGYTRANSPOSED | DATA | 131072 | 28/03/2025 09:06:09 |
2 | ENERGYWITHDETAILS | DATA | 131072 | 28/03/2025 09:11:26 |
3 | FORMATS | CATALOG | 17408 | 28/03/2025 09:07:01 |
4 | RENEWABLEENERGY | DATA | 196608 | 28/03/2025 09:14:20 |
/*This deletes the RenewableEnergy2021 dataset from the WORK library.*/
/*Step 12: Exporting Data with PROC EXPORT*/
/*To share our dataset with others, we might need to export it to an
external file format, such as CSV:*/
proc export data=RenewableEnergy
outfile='/path/to/output/RenewableEnergy.csv'
dbms=csv
replace;
run;
/*This exports the RenewableEnergy dataset to a CSV file at the specified location.*/
- Get link
- X
- Other Apps
Comments
Post a Comment