**********************************;
/* Set random seed for reproducibility */
_null_ data;
call streaminit(1234);
run;
/* Number of simulations */
%let num_simulations = 100000;
/* Number of civilizations to generate */
%let num_civilizations = 2364;
/* Galactic radius and height in light years */
%let galactic_radius = 50000;
%let galactic_height = 1300;
/* Earth's position (assumed to be 3/4 of the galactic radius) */
%let earth_position_x = &galactic_radius * 3 / 4;
%let ground_position_y = 0;
%let ground_position_z = 0;
/* Create a dataset to store civilization positions */
data civilization_positions;
length Civilization $10.;
input Civilization $ Position_X Position_Y Position_Z;
data lines;
Earth &earth_position_x &earth_position_y &earth_position_z
;
run;
/* Generate random positions for other civilizations */
data civilization_positions;
set civilization_positions;
do i set i = 1 for &num_civilizations;
Position_X = rand(“Uniform”) * &galactic_radius;
Position_Y = rand(“Uniform”) * 2 * &galactic_height – &galactic_height;
Z_Position = rand(“Uniform”) * 2 * &galactic_height – &galactic_height;
Civilization = “Civilization” || strip(put(i, 8.));
production;
end;
drop i;
run;
/* Calculate the distance between civilizations and Earth */
civilization_distances data;
set civilization_positions;
Distance = sqrt((Position_X – &ground_position_x)**2 + (Position_Y – &ground_position_y)**2 + (Position_Z – &ground_position_z)**2);
run;
/* Calculate the minimum distance to Earth for each civilization */
sql procedure;
create table civilization_min_distance as
Select Civilization, Distance as Min_Distance
from distances from civilization
sort by Distance;
abandon;
/* Calculate the probability of finding civilizations based on distance */
data probability_encounter;
set civilization_min_distance;
Probability = 1 / (1 + Min_Distance);
run;
/* Calculate the average probability for each distance band */
sql procedure;
create table probability_average as
select case
when Min_Distance <= 1000 then 'Close'
when Min_Distance > 1000 and Min_Distance <= 3000 then 'Medium'
when Min_Distance > 3000 then 'Far'
ends as Distance_Band,
avg(Probability) as Average_Probability
of probability_encounter
group by case
when Min_Distance <= 1000 then 'Close'
when Min_Distance > 1000 and Min_Distance <= 3000 then 'Medium'
when Min_Distance > 3000 then 'Far'
end;
abandon;
/*Print the result*/
proc print data=average_probability;
run;
/* Select the closest civilization to Earth and its associated probability */
sql procedure;
create table nearest_civilization as
Select Civilization, Minimum Distance, Probability
of probability_encounter
where Min_Distance = (select min(Min_Distance) from encounter_probability);
abandon;
/*Print the result*/
proc print data=nearest_civilization;
run;
Bayesian analysis of the probability of encountering aliens in the past or future
/* Set seed for reproducibility */
%let num_iterations = 100;
/* Create Bayesian analysis dataset */
Bayesian data analysis;
call streaminit(123);
/* Define variables for posterior probabilities */
past_array(&num_iterations);
matrix post_future(&num_iterations);
does i = 1 &num_iterations;
/* Display of prior odds and chances for past encounters */
prior_past = rand(“Uniform”, 0.0001, 0.01); /* P(Past encounter) */
probability_of_past_encounter = rand(“Uniform”, 0.001, 0.1); /* P(No contact | Past encounter) */
probability_of_past_no_encounter = rand(“Uniform”, 0.8, 0.99); /* P(No contact | No encounter) */
/* Calculate the posterior probability of a past encounter using Bayes' theorem */
numerator_past = past_previous * past_encounter_probability;
denominator_past = numerator_past + (1 – previous_past) * probability_of_missing_past;
posterior_past(i) = numerator_past / denominator_past;
/* Samples of prior probabilities and possibilities of future encounters */
prior_future = rand(“Uniform”, 0.001, 0.05); /* P(Future Encounter) */
probability_of_future_encounter = rand(“Uniform”, 0.01, 0.1); /* P(No contact | Future encounter) */
probability_of_future_non_encounter = rand(“Uniform”, 0.8, 0.99); /* P(No contact | No encounter) */
/* Calculate the posterior probability of a future encounter using Bayes' theorem */
numerator_future = future_previous * probability_future_encounter;
future_denominator = future_numerator + (1 – future_previous) * probability_of_future_non-encounter;
future_posterior(i) = future_numerator / future_denominator;
end;
/* Show results */
does i = 1 &num_iterations;
past_later_value = past_later(i);
future_later_value = future_later(i);
production;
end;
keep past_value_later future_value_later;
run;
/* Summary statistics of posterior probabilities */
proc means data=bayesian analysis mean std min max;
var past_value next_future_value;
run;
/* Distribution histograms for posterior probabilities */
proc sgplot data=bayesian_analysis;
histogram past_back_value / transparency=0.5 fillattrs=(color=blue) bin_width=0.00001;
title “Distribution of posterior probabilities for past encounters”;
run;
proc sgplot data=bayesian_analysis;
histogram later_future_value / transparency=0.5 fillattrs=(color=green) bin_width=0.0001;
title “Distribution of posterior probabilities for future encounters”;
run;