WORLD HISTORICAL MONUMENTS DATASET CREATION WITH DATE FORMATS | PROC SQL | PROC FREQ | PROC MEANS | PROC SGPLOT | MACRO AUTOMATION | INTNX | INTCK BASED TOURISM CATEGORIZATION AND ANALYTICAL MODELING
options nocenter nodate nonumber;
Step 1: Create a raw dataset of world historical monuments
data work.monuments_raw;
length Monument_Name $40 Country $20 UNESCO_Status $3 Construction_Date_Char $10;
infile datalines dsd truncover;
input Monument_Name :$40. Country :$20. Visitors_per_Year Construction_Year
UNESCO_Status :$3. Entry_Fee Construction_Date_Char :$10. Sample_Visit :date9.;
format Sample_Visit date9. Construction_Date date9. Entry_Fee 8.2;
/* ----- DATE PROTECTION LOGIC ----- */
if Construction_Year >= 1582 then
Construction_Date = mdy(1,1,Construction_Year);
else
Construction_Date = .;
datalines;
"Great Wall of China","China",10000000,0700,"Yes",40,"01JAN0700","15FEB2024"
"Colosseum","Italy",7500000,0800,"Yes",20,"01JAN0800","20APR2024"
"Statue of Liberty","USA",4300000,1886,"Yes",25,"01JAN1886","10MAR2024"
"Taj Mahal","India",9000000,1653,"Yes",50,"01JAN1653","25FEB2024"
"Machu Picchu","Peru",1500000,1450,"Yes",45,"01JAN1450","05MAY2024"
"Eiffel Tower","France",7000000,1889,"Yes",30,"01JAN1889","22APR2024"
"Angkor Wat","Cambodia",2500000,1150,"Yes",37,"01JAN1150","25MAR2024"
"Christ the Redeemer","Brazil",2000000,1931,"Yes",35,"01JAN1931","18FEB2024"
"Acropolis of Athens","Greece",2000000,0500,"Yes",20,"01JAN0500","12APR2024"
"Petra","Jordan",1200000,0300,"Yes",35,"01JAN0300","30MAR2024"
"Stonehenge","UK",1400000,2500,"Yes",28,"01JAN2500","16APR2024"
"Chichen Itza","Mexico",2300000,0600,"Yes",30,"01JAN0600","08MAR2024"
;
run;
proc print data=work.monuments_raw;
run;
OUTPUT:
| Obs | Monument_Name | Country | UNESCO_Status | Construction_Date_Char | Visitors_per_Year | Construction_Year | Entry_Fee | Sample_Visit | Construction_Date |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Great Wall of China | China | Yes | 01JAN0700 | 10000000 | 700 | 40.00 | 15FEB2024 | . |
| 2 | Colosseum | Italy | Yes | 01JAN0800 | 7500000 | 800 | 20.00 | 20APR2024 | . |
| 3 | Statue of Liberty | USA | Yes | 01JAN1886 | 4300000 | 1886 | 25.00 | 10MAR2024 | 01JAN1886 |
| 4 | Taj Mahal | India | Yes | 01JAN1653 | 9000000 | 1653 | 50.00 | 25FEB2024 | 01JAN1653 |
| 5 | Machu Picchu | Peru | Yes | 01JAN1450 | 1500000 | 1450 | 45.00 | 05MAY2024 | . |
| 6 | Eiffel Tower | France | Yes | 01JAN1889 | 7000000 | 1889 | 30.00 | 22APR2024 | 01JAN1889 |
| 7 | Angkor Wat | Cambodia | Yes | 01JAN1150 | 2500000 | 1150 | 37.00 | 25MAR2024 | . |
| 8 | Christ the Redeemer | Brazil | Yes | 01JAN1931 | 2000000 | 1931 | 35.00 | 18FEB2024 | 01JAN1931 |
| 9 | Acropolis of Athens | Greece | Yes | 01JAN0500 | 2000000 | 500 | 20.00 | 12APR2024 | . |
| 10 | Petra | Jordan | Yes | 01JAN0300 | 1200000 | 300 | 35.00 | 30MAR2024 | . |
| 11 | Stonehenge | UK | Yes | 01JAN2500 | 1400000 | 2500 | 28.00 | 16APR2024 | 01JAN2500 |
| 12 | Chichen Itza | Mexico | Yes | 01JAN0600 | 2300000 | 600 | 30.00 | 08MAR2024 | . |
Step 2: Use PROC SQL to create an enhanced dataset
proc sql;
create table work.monuments_sql as
select Monument_Name,Country,Visitors_per_Year,Construction_Year,UNESCO_Status,
Entry_Fee,Construction_Date,Sample_Visit,year(Sample_Visit) as Visit_Year,
/* Age of monument at the time of Sample_Visit */
intck('year', Construction_Date, Sample_Visit) as Age_at_Visit_Years
from work.monuments_raw;
quit;
proc print data=work.monuments_sql;
run;
OUTPUT:
| Obs | Monument_Name | Country | Visitors_per_Year | Construction_Year | UNESCO_Status | Entry_Fee | Construction_Date | Sample_Visit | Visit_Year | Age_at_Visit_Years |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Great Wall of China | China | 10000000 | 700 | Yes | 40.00 | . | 15FEB2024 | 2024 | . |
| 2 | Colosseum | Italy | 7500000 | 800 | Yes | 20.00 | . | 20APR2024 | 2024 | . |
| 3 | Statue of Liberty | USA | 4300000 | 1886 | Yes | 25.00 | 01JAN1886 | 10MAR2024 | 2024 | 138 |
| 4 | Taj Mahal | India | 9000000 | 1653 | Yes | 50.00 | 01JAN1653 | 25FEB2024 | 2024 | 371 |
| 5 | Machu Picchu | Peru | 1500000 | 1450 | Yes | 45.00 | . | 05MAY2024 | 2024 | . |
| 6 | Eiffel Tower | France | 7000000 | 1889 | Yes | 30.00 | 01JAN1889 | 22APR2024 | 2024 | 135 |
| 7 | Angkor Wat | Cambodia | 2500000 | 1150 | Yes | 37.00 | . | 25MAR2024 | 2024 | . |
| 8 | Christ the Redeemer | Brazil | 2000000 | 1931 | Yes | 35.00 | 01JAN1931 | 18FEB2024 | 2024 | 93 |
| 9 | Acropolis of Athens | Greece | 2000000 | 500 | Yes | 20.00 | . | 12APR2024 | 2024 | . |
| 10 | Petra | Jordan | 1200000 | 300 | Yes | 35.00 | . | 30MAR2024 | 2024 | . |
| 11 | Stonehenge | UK | 1400000 | 2500 | Yes | 28.00 | 01JAN2500 | 16APR2024 | 2024 | -476 |
| 12 | Chichen Itza | Mexico | 2300000 | 600 | Yes | 30.00 | . | 08MAR2024 | 2024 | . |
Step 3: More enhancements with INTNX and INTCK
data work.monuments_enhanced;
set work.monuments_sql;
format Years_Since_Construction 8. Next_Year_Visit date9. Anniversary_500 date9.
Years_Until_500 8.;
/* Age from construction to today */
Years_Since_Construction = intck('year', Construction_Date, today());
/* Next year's sample visit date (same day and month) */
Next_Year_Visit = intnx('year', Sample_Visit, 1, 'same');
/* 500-year anniversary (500 years after Construction_Date) */
Anniversary_500 = intnx('year', Construction_Date, 500, 'same');
/* How many years from today until the 500-year anniversary */
Years_Until_500 = intck('year', today(), Anniversary_500);
run;
proc print data=work.monuments_enhanced;
run;
OUTPUT:
| Obs | Monument_Name | Country | Visitors_per_Year | Construction_Year | UNESCO_Status | Entry_Fee | Construction_Date | Sample_Visit | Visit_Year | Age_at_Visit_Years | Years_Since_Construction | Next_Year_Visit | Anniversary_500 | Years_Until_500 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Great Wall of China | China | 10000000 | 700 | Yes | 40.00 | . | 15FEB2024 | 2024 | . | . | 15FEB2025 | . | . |
| 2 | Colosseum | Italy | 7500000 | 800 | Yes | 20.00 | . | 20APR2024 | 2024 | . | . | 20APR2025 | . | . |
| 3 | Statue of Liberty | USA | 4300000 | 1886 | Yes | 25.00 | 01JAN1886 | 10MAR2024 | 2024 | 138 | 139 | 10MAR2025 | 01JAN2386 | 361 |
| 4 | Taj Mahal | India | 9000000 | 1653 | Yes | 50.00 | 01JAN1653 | 25FEB2024 | 2024 | 371 | 372 | 25FEB2025 | 01JAN2153 | 128 |
| 5 | Machu Picchu | Peru | 1500000 | 1450 | Yes | 45.00 | . | 05MAY2024 | 2024 | . | . | 05MAY2025 | . | . |
| 6 | Eiffel Tower | France | 7000000 | 1889 | Yes | 30.00 | 01JAN1889 | 22APR2024 | 2024 | 135 | 136 | 22APR2025 | 01JAN2389 | 364 |
| 7 | Angkor Wat | Cambodia | 2500000 | 1150 | Yes | 37.00 | . | 25MAR2024 | 2024 | . | . | 25MAR2025 | . | . |
| 8 | Christ the Redeemer | Brazil | 2000000 | 1931 | Yes | 35.00 | 01JAN1931 | 18FEB2024 | 2024 | 93 | 94 | 18FEB2025 | 01JAN2431 | 406 |
| 9 | Acropolis of Athens | Greece | 2000000 | 500 | Yes | 20.00 | . | 12APR2024 | 2024 | . | . | 12APR2025 | . | . |
| 10 | Petra | Jordan | 1200000 | 300 | Yes | 35.00 | . | 30MAR2024 | 2024 | . | . | 30MAR2025 | . | . |
| 11 | Stonehenge | UK | 1400000 | 2500 | Yes | 28.00 | 01JAN2500 | 16APR2024 | 2024 | -476 | -475 | 16APR2025 | 01JAN3000 | 975 |
| 12 | Chichen Itza | Mexico | 2300000 | 600 | Yes | 30.00 | . | 08MAR2024 | 2024 | . | . | 08MAR2025 | . | . |
Step 4: Macro for Tourism Categorization
%macro categorize_tourism(in=work.monuments_enhanced,
out=work.monuments_final,
high_visitors=5000000,
low_fee=30);
data &out;
set ∈
length Tourism_Category $20;
if Visitors_per_Year >= &high_visitors and Entry_Fee <= &low_fee then
Tourism_Category = 'Mass Budget';
else if Visitors_per_Year >= &high_visitors and Entry_Fee > &low_fee then
Tourism_Category = 'Premium Mass';
else if Visitors_per_Year < &high_visitors and Entry_Fee > &low_fee then
Tourism_Category = 'Niche Premium';
else
Tourism_Category = 'Niche Budget';
run;
proc print data=&out;
run;
%mend categorize_tourism;
%categorize_tourism();
OUTPUT:
| Obs | Monument_Name | Country | Visitors_per_Year | Construction_Year | UNESCO_Status | Entry_Fee | Construction_Date | Sample_Visit | Visit_Year | Age_at_Visit_Years | Years_Since_Construction | Next_Year_Visit | Anniversary_500 | Years_Until_500 | Tourism_Category |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Great Wall of China | China | 10000000 | 700 | Yes | 40.00 | . | 15FEB2024 | 2024 | . | . | 15FEB2025 | . | . | Premium Mass |
| 2 | Colosseum | Italy | 7500000 | 800 | Yes | 20.00 | . | 20APR2024 | 2024 | . | . | 20APR2025 | . | . | Mass Budget |
| 3 | Statue of Liberty | USA | 4300000 | 1886 | Yes | 25.00 | 01JAN1886 | 10MAR2024 | 2024 | 138 | 139 | 10MAR2025 | 01JAN2386 | 361 | Niche Budget |
| 4 | Taj Mahal | India | 9000000 | 1653 | Yes | 50.00 | 01JAN1653 | 25FEB2024 | 2024 | 371 | 372 | 25FEB2025 | 01JAN2153 | 128 | Premium Mass |
| 5 | Machu Picchu | Peru | 1500000 | 1450 | Yes | 45.00 | . | 05MAY2024 | 2024 | . | . | 05MAY2025 | . | . | Niche Premium |
| 6 | Eiffel Tower | France | 7000000 | 1889 | Yes | 30.00 | 01JAN1889 | 22APR2024 | 2024 | 135 | 136 | 22APR2025 | 01JAN2389 | 364 | Mass Budget |
| 7 | Angkor Wat | Cambodia | 2500000 | 1150 | Yes | 37.00 | . | 25MAR2024 | 2024 | . | . | 25MAR2025 | . | . | Niche Premium |
| 8 | Christ the Redeemer | Brazil | 2000000 | 1931 | Yes | 35.00 | 01JAN1931 | 18FEB2024 | 2024 | 93 | 94 | 18FEB2025 | 01JAN2431 | 406 | Niche Premium |
| 9 | Acropolis of Athens | Greece | 2000000 | 500 | Yes | 20.00 | . | 12APR2024 | 2024 | . | . | 12APR2025 | . | . | Niche Budget |
| 10 | Petra | Jordan | 1200000 | 300 | Yes | 35.00 | . | 30MAR2024 | 2024 | . | . | 30MAR2025 | . | . | Niche Premium |
| 11 | Stonehenge | UK | 1400000 | 2500 | Yes | 28.00 | 01JAN2500 | 16APR2024 | 2024 | -476 | -475 | 16APR2025 | 01JAN3000 | 975 | Niche Budget |
| 12 | Chichen Itza | Mexico | 2300000 | 600 | Yes | 30.00 | . | 08MAR2024 | 2024 | . | . | 08MAR2025 | . | . | Niche Budget |
Step 5: Frequency analysis
proc freq data=work.monuments_final;
tables Country UNESCO_Status Tourism_Category
UNESCO_Status*Tourism_Category / nocum nopercent;
run;
OUTPUT:
The FREQ Procedure
| Country | Frequency |
|---|---|
| Brazil | 1 |
| Cambodia | 1 |
| China | 1 |
| France | 1 |
| Greece | 1 |
| India | 1 |
| Italy | 1 |
| Jordan | 1 |
| Mexico | 1 |
| Peru | 1 |
| UK | 1 |
| USA | 1 |
| UNESCO_Status | Frequency |
|---|---|
| Yes | 12 |
| Tourism_Category | Frequency |
|---|---|
| Mass Budget | 2 |
| Niche Budget | 4 |
| Niche Premium | 4 |
| Premium Mass | 2 |
|
| ||||||||||||||||||||||||||||||
Step 6: Numeric summary with PROC MEANS
proc means data=work.monuments_final n mean median min max maxdec=2;
var Visitors_per_Year Entry_Fee Years_Since_Construction;
run;
OUTPUT:
The MEANS Procedure
| Variable | N | Mean | Median | Minimum | Maximum |
|---|---|---|---|---|---|
Visitors_per_Year Entry_Fee Years_Since_Construction | 12 12 5 | 4225000.00 32.92 53.20 | 2400000.00 32.50 136.00 | 1200000.00 20.00 -475.00 | 10000000.00 50.00 372.00 |
/* By country */
proc means data=work.monuments_final n mean min max maxdec=2;
class Country;
var Visitors_per_Year Entry_Fee;
run;
OUTPUT:
The MEANS Procedure
| Country | N Obs | Variable | N | Mean | Minimum | Maximum |
|---|---|---|---|---|---|---|
| Brazil | 1 | Visitors_per_Year Entry_Fee | 1 1 | 2000000.00 35.00 | 2000000.00 35.00 | 2000000.00 35.00 |
| Cambodia | 1 | Visitors_per_Year Entry_Fee | 1 1 | 2500000.00 37.00 | 2500000.00 37.00 | 2500000.00 37.00 |
| China | 1 | Visitors_per_Year Entry_Fee | 1 1 | 10000000.00 40.00 | 10000000.00 40.00 | 10000000.00 40.00 |
| France | 1 | Visitors_per_Year Entry_Fee | 1 1 | 7000000.00 30.00 | 7000000.00 30.00 | 7000000.00 30.00 |
| Greece | 1 | Visitors_per_Year Entry_Fee | 1 1 | 2000000.00 20.00 | 2000000.00 20.00 | 2000000.00 20.00 |
| India | 1 | Visitors_per_Year Entry_Fee | 1 1 | 9000000.00 50.00 | 9000000.00 50.00 | 9000000.00 50.00 |
| Italy | 1 | Visitors_per_Year Entry_Fee | 1 1 | 7500000.00 20.00 | 7500000.00 20.00 | 7500000.00 20.00 |
| Jordan | 1 | Visitors_per_Year Entry_Fee | 1 1 | 1200000.00 35.00 | 1200000.00 35.00 | 1200000.00 35.00 |
| Mexico | 1 | Visitors_per_Year Entry_Fee | 1 1 | 2300000.00 30.00 | 2300000.00 30.00 | 2300000.00 30.00 |
| Peru | 1 | Visitors_per_Year Entry_Fee | 1 1 | 1500000.00 45.00 | 1500000.00 45.00 | 1500000.00 45.00 |
| UK | 1 | Visitors_per_Year Entry_Fee | 1 1 | 1400000.00 28.00 | 1400000.00 28.00 | 1400000.00 28.00 |
| USA | 1 | Visitors_per_Year Entry_Fee | 1 1 | 4300000.00 25.00 | 4300000.00 25.00 | 4300000.00 25.00 |
Step 7: Scatter plot of visitors vs. entry fee
proc sgplot data=work.monuments_final;
scatter x=Entry_Fee y=Visitors_per_Year / group=UNESCO_Status;
xaxis label="Entry Fee";
yaxis label="Visitors per Year";
title "Visitors vs Entry Fee by UNESCO Status";
run;
OUTPUT:
/* Bar chart: total visitors per country */
proc sgplot data=work.monuments_final;
vbar Country / response=Visitors_per_Year stat=sum;
yaxis label="Total Visitors per Year";
title "Total Annual Visitors by Country";
run;
No comments:
Post a Comment