287.COMPREHENSIVE UREA ANALYSIS IN SAS: FROM DATASET CREATION TO CHEMICAL INSIGHTS USING DATA INPUT | LABELING | CONDITIONAL LOGIC | SUBSETTING | GROUP STATISTICS | FREQUENCY ANALYSIS | TITLE REPORTING | CHEMICAL CALCULATIONS
COMPREHENSIVE UREA ANALYSIS IN SAS: FROM DATASET CREATION TO CHEMICAL INSIGHTS USING DATA INPUT | LABELING | CONDITIONAL LOGIC | SUBSETTING | GROUP STATISTICS | FREQUENCY ANALYSIS | TITLE REPORTING | CHEMICAL CALCULATIONS
1.Creating a dataset to represent different types of urea and their properties
options nocenter;
data urea_types;
/* Defining variables and their types */
length Urea_Type $10 Application $20;
input Urea_Type $ Purity Moisture_Content Nitrogen_Content Particle_Size Application $;
/* Assigning labels and formats for reporting clarity */
label
Urea_Type = "Type of Urea (Prilled, Granular, etc)"
Purity = "Purity (%)"
Moisture_Content = "Moisture Content (%)"
Nitrogen_Content = "Nitrogen Content (%)"
Particle_Size = "Particle Size (mm)"
Application = "Main Application Field"
Quality_Class = "Quality Classification Based on Purity and Moisture";
format Purity 6.2 Moisture_Content 6.2 Nitrogen_Content 6.2 Particle_Size 5.2;
/* Deriving a new variable: Quality_Class */
if Purity >= 99.0 and Moisture_Content <= 0.5 then Quality_Class = "Premium";
else if Purity >= 95.0 and Moisture_Content <= 1.0 then Quality_Class = "Standard";
else Quality_Class = "Industrial";
/* Calculating Derived Nitrogen Mass for a standard sample (in grams) */
Nitrogen_Mass = Nitrogen_Content * 1.0; /* Assuming sample mass is 1g for calculation */
datalines;
Prilled 99.5 0.30 46.0 1.00 Fertilizer
Granular 98.0 0.80 45.7 2.50 Agriculture
Medical 99.9 0.10 46.2 0.50 Pharmaceutical
Industrial 94.0 1.50 44.0 3.00 Chemical_Industry
Feed 97.0 0.60 45.2 1.20 Animal_Nutrition
LowGrade 92.5 1.80 43.5 4.00 Miscellaneous
;
run;
proc print;run;
Output:
| Obs | Urea_Type | Application | Purity | Moisture_Content | Nitrogen_Content | Particle_Size | Quality_Class | Nitrogen_Mass |
|---|---|---|---|---|---|---|---|---|
| 1 | Prilled | Fertilizer | 99.50 | 0.30 | 46.00 | 1.00 | Premium | 46.0 |
| 2 | Granular | Agriculture | 98.00 | 0.80 | 45.70 | 2.50 | Standar | 45.7 |
| 3 | Medical | Pharmaceutical | 99.90 | 0.10 | 46.20 | 0.50 | Premium | 46.2 |
| 4 | Industrial | Chemical_Industry | 94.00 | 1.50 | 44.00 | 3.00 | Industr | 44.0 |
| 5 | Feed | Animal_Nutrition | 97.00 | 0.60 | 45.20 | 1.20 | Standar | 45.2 |
| 6 | LowGrade | Miscellaneous | 92.50 | 1.80 | 43.50 | 4.00 | Industr | 43.5 |
2.Subsetting dataset for Premium grade urea
data premium_urea;
set urea_types;
where Quality_Class = "Premium";
run;
proc print;run;
Output:
| Obs | Urea_Type | Application | Purity | Moisture_Content | Nitrogen_Content | Particle_Size | Quality_Class | Nitrogen_Mass |
|---|---|---|---|---|---|---|---|---|
| 1 | Prilled | Fertilizer | 99.50 | 0.30 | 46.00 | 1.00 | Premium | 46.0 |
| 2 | Medical | Pharmaceutical | 99.90 | 0.10 | 46.20 | 0.50 | Premium | 46.2 |
3.Create a summary dataset with average values grouped by Application type
proc means data=urea_types noprint;
class Application;
var Purity Moisture_Content Nitrogen_Content Particle_Size;
output out=application_summary mean=Avg_Purity Avg_Moisture Avg_Nitrogen Avg_Particle;
run;
proc print;run;
Output:
| Obs | Application | _TYPE_ | _FREQ_ | Avg_Purity | Avg_Moisture | Avg_Nitrogen | Avg_Particle |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 6 | 96.82 | 0.85 | 45.10 | 2.03 | |
| 2 | Agriculture | 1 | 1 | 98.00 | 0.80 | 45.70 | 2.50 |
| 3 | Animal_Nutrition | 1 | 1 | 97.00 | 0.60 | 45.20 | 1.20 |
| 4 | Chemical_Industry | 1 | 1 | 94.00 | 1.50 | 44.00 | 3.00 |
| 5 | Fertilizer | 1 | 1 | 99.50 | 0.30 | 46.00 | 1.00 |
| 6 | Miscellaneous | 1 | 1 | 92.50 | 1.80 | 43.50 | 4.00 |
| 7 | Pharmaceutical | 1 | 1 | 99.90 | 0.10 | 46.20 | 0.50 |
4. Generate a frequency table for types of urea
proc freq data=urea_types;
tables Urea_Type Application Quality_Class;
run;
Output:
The FREQ Procedure
| Type of Urea (Prilled, Granular, etc) | ||||
|---|---|---|---|---|
| Urea_Type | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| Feed | 1 | 16.67 | 1 | 16.67 |
| Granular | 1 | 16.67 | 2 | 33.33 |
| Industrial | 1 | 16.67 | 3 | 50.00 |
| LowGrade | 1 | 16.67 | 4 | 66.67 |
| Medical | 1 | 16.67 | 5 | 83.33 |
| Prilled | 1 | 16.67 | 6 | 100.00 |
| Main Application Field | ||||
|---|---|---|---|---|
| Application | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| Agriculture | 1 | 16.67 | 1 | 16.67 |
| Animal_Nutrition | 1 | 16.67 | 2 | 33.33 |
| Chemical_Industry | 1 | 16.67 | 3 | 50.00 |
| Fertilizer | 1 | 16.67 | 4 | 66.67 |
| Miscellaneous | 1 | 16.67 | 5 | 83.33 |
| Pharmaceutical | 1 | 16.67 | 6 | 100.00 |
| Quality Classification Based on Purity and Moisture | ||||
|---|---|---|---|---|
| Quality_Class | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| Industr | 2 | 33.33 | 2 | 33.33 |
| Premium | 2 | 33.33 | 4 | 66.67 |
| Standar | 2 | 33.33 | 6 | 100.00 |
5.Generating a simple printout with title
proc print data=urea_types label;
title "Urea Types Dataset with Properties and Application";
run;
Output:
| Obs | Type of Urea (Prilled, Granular, etc) | Main Application Field | Purity (%) | Moisture Content (%) | Nitrogen Content (%) | Particle Size (mm) | Quality Classification Based on Purity and Moisture | Nitrogen_Mass |
|---|---|---|---|---|---|---|---|---|
| 1 | Prilled | Fertilizer | 99.50 | 0.30 | 46.00 | 1.00 | Premium | 46.0 |
| 2 | Granular | Agriculture | 98.00 | 0.80 | 45.70 | 2.50 | Standar | 45.7 |
| 3 | Medical | Pharmaceutical | 99.90 | 0.10 | 46.20 | 0.50 | Premium | 46.2 |
| 4 | Industrial | Chemical_Industry | 94.00 | 1.50 | 44.00 | 3.00 | Industr | 44.0 |
| 5 | Feed | Animal_Nutrition | 97.00 | 0.60 | 45.20 | 1.20 | Standar | 45.2 |
| 6 | LowGrade | Miscellaneous | 92.50 | 1.80 | 43.50 | 4.00 | Industr | 43.5 |
6.Display summary statistics for Premium Urea
proc print data=application_summary;
where Application = "Fertilizer";
run;
Output:
| Obs | Application | _TYPE_ | _FREQ_ | Avg_Purity | Avg_Moisture | Avg_Nitrogen | Avg_Particle |
|---|---|---|---|---|---|---|---|
| 5 | Fertilizer | 1 | 1 | 99.50 | 0.30 | 46.00 | 1.00 |
7.Example of deriving additional chemical info for each type
data chemical_analysis;
set urea_types;
/* Calculation of urea molecular mass */
Urea_Molecular_Mass = 60.06;
Urea_Content_g_per_kg = (Purity/100) * 1000;
/* Ratio of nitrogen to urea mass */
Nitrogen_Urea_Ratio = Nitrogen_Content / (Purity);
run;
proc print data=chemical_analysis label;
title "Chemical Analysis of Urea Types";
run;
| Obs | Type of Urea (Prilled, Granular, etc) | Main Application Field | Purity (%) | Moisture Content (%) | Nitrogen Content (%) | Particle Size (mm) | Quality Classification Based on Purity and Moisture | Nitrogen_Mass | Urea_Molecular_Mass | Urea_Content_g_per_kg | Nitrogen_Urea_Ratio |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Prilled | Fertilizer | 99.50 | 0.30 | 46.00 | 1.00 | Premium | 46.0 | 60.06 | 995 | 0.46231 |
| 2 | Granular | Agriculture | 98.00 | 0.80 | 45.70 | 2.50 | Standar | 45.7 | 60.06 | 980 | 0.46633 |
| 3 | Medical | Pharmaceutical | 99.90 | 0.10 | 46.20 | 0.50 | Premium | 46.2 | 60.06 | 999 | 0.46246 |
| 4 | Industrial | Chemical_Industry | 94.00 | 1.50 | 44.00 | 3.00 | Industr | 44.0 | 60.06 | 940 | 0.46809 |
| 5 | Feed | Animal_Nutrition | 97.00 | 0.60 | 45.20 | 1.20 | Standar | 45.2 | 60.06 | 970 | 0.46598 |
| 6 | LowGrade | Miscellaneous | 92.50 | 1.80 | 43.50 | 4.00 | Industr | 43.5 | 60.06 | 925 | 0.47027 |
Comments
Post a Comment