libname cPoints "&location." access=readonly;

data p_age 					(index=(agegroup)); 
	set cPoints.p_age; 
run;

data p_mdc 					(index=(an120mdc_ra)); 
	set cPoints.p_mdc; 
run;

data p_flag_ICUHours 		(index=(flag_ICUHours)); 
	set cPoints.p_flag_ICUHours; 
run;

/*----------------------------------------------------------------------------
	Starting disaggregate risk factor import block
-----------------------------------------------------------------------------*/

data p_cc_acute_myo 	(index=(cc_acute_myocardial_function)); 
	set cPoints.p_cc_acute_myo; 
run;

data p_cc_cancer 	(index=(cc_cancer)); 
	set cPoints.p_cc_cancer; 
run;

data p_cc_cerebral_vasc 	(index=(cc_cerebral_vascular_accident)); 
	set cPoints.p_cc_cerebral_vasc; 
run;

data p_cc_congestive_heart_failur 	(index=(cc_congestive_heart_failure)); 
	set cPoints.p_cc_congestive_heart_failur; 
run;

data p_cc_connective_tissue 	(index=(cc_connective_tissue_disorder)); 
	set cPoints.p_cc_connective_tissue; 
run;

data p_cc_dementia 	(index=(cc_dementia)); 
	set cPoints.p_cc_dementia; 
run;

data p_cc_diabetes 	(index=(cc_diabetes)); 
	set cPoints.p_cc_diabetes; 
run;

data p_cc_diabetes_comp 	(index=(cc_diabetes_complications)); 
	set cPoints.p_cc_diabetes_comp; 
run;

data p_cc_hiv 	(index=(cc_hiv)); 
	set cPoints.p_cc_hiv; 
run;

data p_cc_liver_disease 	(index=(cc_liver_disease)); 
	set cPoints.p_cc_liver_disease; 
run;

data p_cc_metastatic_cancer 	(index=(cc_metastatic_cancer)); 
	set cPoints.p_cc_metastatic_cancer; 
run;

data p_cc_paraplegia 	(index=(cc_paraplegia)); 
	set cPoints.p_cc_paraplegia; 
run;

data p_cc_peptic_ulcer 	(index=(cc_peptic_ulcer)); 
	set cPoints.p_cc_peptic_ulcer; 
run;

data p_cc_peripheral_vasc 	(index=(cc_peripheral_vascular_disease)); 
	set cPoints.p_cc_peripheral_vasc; 
run;

data p_cc_pulmonary 	(index=(cc_pulmonary_disease)); 
	set cPoints.p_cc_pulmonary; 
run;

data p_cc_renal_disease 	(index=(cc_renal_disease)); 
	set cPoints.p_cc_renal_disease; 
run;

data p_cc_severe_liver 	(index=(cc_severe_liver_disease)); 
	set cPoints.p_cc_severe_liver; 
run;


/*----------------------------------------------------------------------------
	Ending disaggregate risk factor import block
-----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
	Additional Risk Factors for NEP26 
-----------------------------------------------------------------------------*/

data p_cc_Obesity    (index=(cc_Obesity)); 
set cPoints.p_cc_Obesity;   
run;

data p_cc_Cystic_fibrosis    (index=(cc_Cystic_fibrosis)); 
set cPoints.p_cc_Cystic_fibrosis;   
run;

data p_cc_Schizophrenia    (index=(cc_Schizophrenia)); 
set cPoints.p_cc_Schizophrenia;   
run;

data p_cc_Depression    (index=(cc_Depression)); 
set cPoints.p_cc_Depression;   
run;

data p_cc_Disorder_of_intellec    (index=(cc_Disorder_of_intellectual)); 
set cPoints.p_cc_Disorder_of_intellec;   
run;

data p_cc_Parkinsons_disease    (index=(cc_Parkinsons_disease)); 
set cPoints.p_cc_Parkinsons_disease;   
run;

data p_cc_Multiple_sclerosis    (index=(cc_Multiple_sclerosis)); 
set cPoints.p_cc_Multiple_sclerosis;   
run;

data p_cc_Epilepsy    (index=(cc_Epilepsy)); 
set cPoints.p_cc_Epilepsy;   
run;

data p_cc_Cerebral_palsy    (index=(cc_Cerebral_palsy)); 
set cPoints.p_cc_Cerebral_palsy;   
run;

data p_cc_Ischaemic_heart_dise    (index=(cc_Ischaemic_heart_disease)); 
set cPoints.p_cc_Ischaemic_heart_dise;   
run;

data p_cc_Chronic_heart_failur    (index=(cc_Chronic_heart_failure)); 
set cPoints.p_cc_Chronic_heart_failur;   
run;

data p_cc_Hypertension    (index=(cc_Hypertension)); 
set cPoints.p_cc_Hypertension;   
run;

data p_cc_Emphysema_without_CO    (index=(cc_Emphysema_without_COPD)); 
set cPoints.p_cc_Emphysema_without_CO;   
run;

data p_cc_COPD    (index=(cc_COPD)); 
set cPoints.p_cc_COPD;   
run;

data p_cc_Asthma_without_COPD    (index=(cc_Asthma_without_COPD)); 
set cPoints.p_cc_Asthma_without_COPD;   
run;

data p_cc_Bronchiectasis_witho    (index=(cc_Bronchiectasis_without_CF)); 
set cPoints.p_cc_Bronchiectasis_witho;   
run;

data p_cc_Chronic_respiratory_    (index=(cc_Chronic_respiratory_failure)); 
set cPoints.p_cc_Chronic_respiratory_;   
run;

data p_cc_Crohns_disease    (index=(cc_Crohns_disease)); 
set cPoints.p_cc_Crohns_disease;   
run;

data p_cc_Ulcerative_colitis    (index=(cc_Ulcerative_colitis)); 
set cPoints.p_cc_Ulcerative_colitis;   
run;

data p_cc_Chronic_liver_failur    (index=(cc_Chronic_liver_failure)); 
set cPoints.p_cc_Chronic_liver_failur;   
run;

data p_cc_Rheumatoid_arthritis    (index=(cc_Rheumatoid_arthritis)); 
set cPoints.p_cc_Rheumatoid_arthritis;   
run;

data p_cc_Arthritis_and_osteoa    (index=(cc_Arthritis_and_osteoarthritis)); 
set cPoints.p_cc_Arthritis_and_osteoa;   
run;

data p_cc_Systemic_lupus_eryth    (index=(cc_Systemic_lupus_erythematosus)); 
set cPoints.p_cc_Systemic_lupus_eryth;   
run;

data p_cc_Osteoporosis    (index=(cc_Osteoporosis)); 
set cPoints.p_cc_Osteoporosis;   
run;

data p_cc_Chronic_kidney_disea    (index=(cc_Chronic_kidney_disease)); 
set cPoints.p_cc_Chronic_kidney_disea;   
run;

data p_cc_Spina_bifida    (index=(cc_Spina_bifida)); 
set cPoints.p_cc_Spina_bifida;   
run;

data p_cc_Downs_syndrome    (index=(cc_Downs_syndrome)); 
set cPoints.p_cc_Downs_syndrome;   
run;

data p_mental_health    (index=(mental_health)); 
set cPoints.p_mental_health;   
run;

data p_homeless    (index=(homeless)); 
set cPoints.p_homeless;   
run;

data p_post_transplant    (index=(post_transplant)); 
set cPoints.p_post_transplant;   
run;

data p_pacemaker    (index=(pacemaker)); 
set cPoints.p_pacemaker;   
run;

data p_ventilator    (index=(ventilator)); 
set cPoints.p_ventilator;   
run;

data p_asthma    (index=(asthma)); 
set cPoints.p_asthma;   
run;

data p_malnutrition    (index=(malnutrition)); 
set cPoints.p_malnutrition;   
run;

data p_drug_use    (index=(drug_use)); 
set cPoints.p_drug_use;   
run;

data p_dystocia    (index=(dystocia)); 
set cPoints.p_dystocia;   
run;

data p_low_los_flag    (index=(low_los_flag)); 
set cPoints.p_low_los_flag;  
run;

data p__pat_covid_flag    (index=(_pat_covid_flag)); 
set cPoints.p__pat_covid_flag;   
run;

/*----------------------------------------------------------------------------
	Ending additional risk factors for nep26 block
-----------------------------------------------------------------------------*/

data p_flag_AdmTransfer 	(index=(flag_AdmTransfer)); 
	set cPoints.p_flag_AdmTransfer; 
run;

data p_flag_emergency 		(index=(flag_emergency)); 
	set cPoints.p_flag_emergency; 
run;

data p_sex 				(index=(sex_cat)); 
	set cPoints.p_sex; 
run;

data p_DRG12_type 		(index=(DRG12_type)); 
	set cPoints.p_DRG12_type; 
run;

data p_age15 				(index=(age_15g));
	set cPoints.p_age15; 
run;

data p_flag_foetal_distress	(index=(flag_foetal_distress));
	set cPoints.p_flag_foetal_distress; 
run;

data p_flag_PPOP 			(index=(flag_PPOP));
	set cPoints.p_flag_PPOP; 
run;

data p_flag_primiparity 	(index=(flag_primiparity));
	set cPoints.p_flag_primiparity; 
run;

data p_flag_instrument_use	(index=(flag_instrument_use));
	set cPoints.p_flag_instrument_use; 
run;

/*MH - NEP24 - 64 HAC disaggregate: Updated macro loop to account for individual risk factors. */
%macro loop;
%let list = 01 02 03 04 06 07 08 09 10 11 12 13 14	;
	
	%let k=1;
	%do %while(%scan(&list., &k.) ne );
		%let hh = %scan(&list., &k.);
		hac_points&hh. = round(sum(		0
								,_p_intercept&hh.
								,_p_agegroup&hh.
								,_p_an120mdc_RA&hh.
								,_p_flag_ICUHours&hh.
								/*,_p_Charlson_Score&hh.*/
								, _p_cc_Acute_myo&hh.
								, _p_cc_Congestive_heart_failur&hh.
								, _p_cc_Peripheral_vasc&hh.
								, _p_cc_Cerebral_vasc&hh.
								, _p_cc_Dementia&hh.
								, _p_cc_Pulmonary&hh.
								, _p_cc_Connective_tissue&hh.
								, _p_cc_Peptic_ulcer&hh.
								, _p_cc_Liver_disease&hh.
								, _p_cc_Diabetes&hh.
								, _p_cc_Diabetes_comp&hh.
								, _p_cc_Paraplegia&hh.
								, _p_cc_Renal_disease&hh.
								, _p_cc_Cancer&hh.
								, _p_cc_Metastatic_cancer&hh.
								, _p_cc_Severe_liver&hh.
								, _p_cc_HIV&hh.

								,_p_flag_AdmTransfer&hh.
								,_p_flag_emergency&hh.
								,_p_sex_cat&hh.
								,_p_drg12_type&hh.
								
								, _p_cc_Obesity&hh.
								, _p_cc_Cystic_fibrosis&hh.
								, _p_cc_Schizophrenia&hh.
								, _p_cc_Depression&hh.
								, _p_cc_Disorder_of_intellec&hh.
								, _p_cc_parkinsons_disease&hh.
								, _p_cc_Multiple_sclerosis&hh.
								, _p_cc_Epilepsy&hh.
								, _p_cc_Cerebral_palsy&hh.
								, _p_cc_Ischaemic_heart_dise&hh.
								, _p_cc_Chronic_heart_failur&hh.
								, _p_cc_Hypertension&hh.
								, _p_cc_Emphysema_without_CO&hh.
								, _p_cc_COPD&hh.
								, _p_cc_Asthma_without_COPD&hh.
								, _p_cc_Bronchiectasis_witho&hh.
								, _p_cc_Chronic_respiratory_&hh.
								, _p_cc_Crohns_disease&hh.
								, _p_cc_Ulcerative_colitis&hh.
								, _p_cc_Chronic_liver_failur&hh.
								, _p_cc_Rheumatoid_arthritis&hh.
								, _p_cc_Arthritis_and_osteoa&hh.
								, _p_cc_Systemic_lupus_eryth&hh.
								, _p_cc_Osteoporosis&hh.
								, _p_cc_Chronic_kidney_disea&hh.
								, _p_cc_Spina_bifida&hh.
								, _p_cc_Downs_syndrome&hh.
								, _p_mental_health&hh.
								, _p_homeless&hh.
								, _p_post_transplant&hh.
								, _p_pacemaker&hh.
								, _p_ventilator&hh.
								, _p_asthma&hh.
								, _p_malnutrition&hh.
								, _p_drug_use&hh.
								, _p_dystocia&hh.
								, _p_low_los_flag&hh.
								, _p__pat_covid_flag&hh.

							  )
						  );
		%let k = %eval(&k.+1);
	%end;
%mend loop;
data &output.0;
	if _n_ eq 1 then set cPoints.p_intercept;
	set &input.;

	set p_age 				key=agegroup/unique;  			if _error_ ne 0 then do; _error_ = 0; nomatch_age=1; 			end;
	set p_mdc		 		key=an120mdc_ra/unique;  		if _error_ ne 0 then do; _error_ = 0; nomatch_mdc=1;			end;
	set p_flag_ICUHours 	key=flag_ICUHours/unique; 		if _error_ ne 0 then do; _error_ = 0; nomatch_icu=1; 			end;
/*	set p_cc 				key=Charlson_Score/unique;  	if _error_ ne 0 then do; _error_ = 0; nomatch_cc=1; 			end;*/
	set p_cc_Acute_myo        	key=cc_Acute_myocardial_function/unique;        if _error_ ne 0 then do;  _error_=0; nomatch_Acute_myocardial=1;            end; else nomatch_Acute_myo=0;
	set p_cc_Congestive_heart_failur       	key=cc_Congestive_heart_failure/unique;         if _error_ ne 0 then do;  _error_=0; nomatch_Congestive_heart_failur=1;            end; else nomatch_Congestive_heart_failur=0;
	set p_cc_Peripheral_vasc     	key=cc_Peripheral_vascular_disease/unique;      if _error_ ne 0 then do;  _error_=0; nomatch_Peripheral_vasc=1;          	end; else nomatch_Peripheral_vascular=0;
	set p_cc_Cerebral_vasc       	key=cc_Cerebral_vascular_accident/unique;       if _error_ ne 0 then do;  _error_=0; nomatch_Cerebral_vasc=1;            	end; else nomatch_Cerebral_vascular=0;
	set p_cc_Dementia       					key=cc_Dementia/unique;        				 	if _error_ ne 0 then do;  _error_=0; nomatch_Dementia=1;             		end; else nomatch_Dementia=0;
	set p_cc_Pulmonary       		 	key=cc_Pulmonary_disease/unique;        		if _error_ ne 0 then do;  _error_=0; nomatch_Pulmonary=1;            		end; else nomatch_Pulmonary=0;
	set p_cc_Connective_tissue       	key=cc_Connective_tissue_disorder/unique;       if _error_ ne 0 then do;  _error_=0; nomatch_Connective_tissue=1;           end; else nomatch_Connective_tissue=0;
	set p_cc_Peptic_ulcer      				 	key=cc_Peptic_ulcer/unique;        			 	if _error_ ne 0 then do;  _error_=0; nomatch_Peptic_ulcer=1;             	end; else nomatch_Peptic_ulcer=0;
	set p_cc_Liver_disease     				 	key=cc_Liver_disease/unique;        			if _error_ ne 0 then do;  _error_=0; nomatch_Liver_disease=1;           	end; else nomatch_Liver_disease=0;
	set p_cc_Diabetes       					key=cc_Diabetes/unique;        				 	if _error_ ne 0 then do;  _error_=0; nomatch_Diabetes=1;            		end; else nomatch_Diabetes=0;
	set p_cc_Diabetes_comp       		key=cc_Diabetes_complications/unique;         	if _error_ ne 0 then do;  _error_=0; nomatch_Diabetes_comp=1;           	end; else nomatch_Diabetes_comp=0;
	set p_cc_Paraplegia       				 	key=cc_Paraplegia/unique;       				if _error_ ne 0 then do;  _error_=0; nomatch_Paraplegia=1;           		end; else nomatch_Paraplegia=0;
	set p_cc_Renal_disease       			 	key=cc_Renal_disease/unique;    			    if _error_ ne 0 then do;  _error_=0; nomatch_Renal_disease=1;         	    end; else nomatch_Renal_disease=0;
	set p_cc_Cancer       					 	key=cc_Cancer/unique;        					if _error_ ne 0 then do;  _error_=0; nomatch_Cancer=1;             		  	end; else nomatch_Cancer=0;
	set p_cc_Metastatic_cancer       		 	key=cc_Metastatic_cancer/unique;        		if _error_ ne 0 then do;  _error_=0; nomatch_Metastatic_cancer=1;          	end; else nomatch_Metastatic_cancer=0;
	set p_cc_Severe_liver       		key=cc_Severe_liver_disease/unique;        	 	if _error_ ne 0 then do;  _error_=0; nomatch_Severe_liver=1;            	end; else nomatch_Severe_liver=0;
	set p_cc_HIV       						 	key=cc_HIV/unique;        						if _error_ ne 0 then do;  _error_=0; nomatch_HIV=1;           				end; else nomatch_HIV=0;

	set p_flag_AdmTransfer 	key=flag_AdmTransfer/unique; 	if _error_ ne 0 then do; _error_ = 0; nomatch_tfr=1; 			end;
	set p_flag_emergency 	key=flag_emergency/unique;  	if _error_ ne 0 then do; _error_ = 0; nomatch_emergency=1;		end;
	set p_sex 				key=sex_cat/unique;  					if _error_ ne 0 then do; _error_ = 0; nomatch_sex=1; 		end;
	set p_drg12_type 		key=drg12_type/unique;  		if _error_ ne 0 then do; _error_ = 0; nomatch_drg12=1; 			end;

	set p_cc_Obesity key=cc_Obesity/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Obesity =1; end; else nomatch_cc_Obesity=0;
	set p_cc_Cystic_fibrosis key=cc_Cystic_fibrosis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Cystic_fibrosis =1; end; else nomatch_cc_Cystic_fibrosis=0;
	set p_cc_Schizophrenia key=cc_Schizophrenia/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Schizophrenia =1; end; else nomatch_cc_Schizophrenia=0;
	set p_cc_Depression key=cc_Depression/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Depression =1; end; else nomatch_cc_Depression=0;
	set p_cc_Disorder_of_intellec key=cc_Disorder_of_intellectual/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Disorder_of_intellec =1; end; else nomatch_cc_Disorder_of_intellec=0;
	set p_cc_Parkinsons_disease key=cc_Parkinsons_disease/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Parkinsons_disease =1; end; else nomatch_cc_Parkinsons_disease=0;
	set p_cc_Multiple_sclerosis key=cc_Multiple_sclerosis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Multiple_sclerosis =1; end; else nomatch_cc_Multiple_sclerosis=0;
	set p_cc_Epilepsy key=cc_Epilepsy/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Epilepsy =1; end; else nomatch_cc_Epilepsy=0;
	set p_cc_Cerebral_palsy key=cc_Cerebral_palsy/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Cerebral_palsy =1; end; else nomatch_cc_Cerebral_palsy=0;
	set p_cc_Ischaemic_heart_dise key=cc_Ischaemic_heart_disease/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Ischaemic_heart_dise =1; end; else nomatch_cc_Ischaemic_heart_dise=0;
	set p_cc_Chronic_heart_failur key=cc_Chronic_heart_failure/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Chronic_heart_failur =1; end; else nomatch_cc_Chronic_heart_failur=0;
	set p_cc_Hypertension key=cc_Hypertension/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Hypertension =1; end; else nomatch_cc_Hypertension=0;
	set p_cc_Emphysema_without_CO key=cc_Emphysema_without_COPD/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Emphysema_without_CO =1; end; else nomatch_cc_Emphysema_without_CO=0;
	set p_cc_COPD key=cc_COPD/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_COPD =1; end; else nomatch_cc_COPD=0;
	set p_cc_Asthma_without_COPD key=cc_Asthma_without_COPD/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Asthma_without_COPD =1; end; else nomatch_cc_Asthma_without_COPD=0;
	set p_cc_Bronchiectasis_witho key=cc_Bronchiectasis_without_CF/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Bronchiectasis_witho =1; end; else nomatch_cc_Bronchiectasis_witho=0;
	set p_cc_Chronic_respiratory_ key=cc_Chronic_respiratory_failure/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Chronic_respiratory_ =1; end; else nomatch_cc_Chronic_respiratory_=0;
	set p_cc_Crohns_disease key=cc_Crohns_disease/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Crohns_disease =1; end; else nomatch_cc_Crohns_disease=0;
	set p_cc_Ulcerative_colitis key=cc_Ulcerative_colitis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Ulcerative_colitis =1; end; else nomatch_cc_Ulcerative_colitis=0;
	set p_cc_Chronic_liver_failur key=cc_Chronic_liver_failure/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Chronic_liver_failur =1; end; else nomatch_cc_Chronic_liver_failur=0;
	set p_cc_Rheumatoid_arthritis key=cc_Rheumatoid_arthritis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Rheumatoid_arthritis =1; end; else nomatch_cc_Rheumatoid_arthritis=0;
	set p_cc_Arthritis_and_osteoa key=cc_Arthritis_and_osteoarthritis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Arthritis_and_osteoa =1; end; else nomatch_cc_Arthritis_and_osteoa=0;
	set p_cc_Systemic_lupus_eryth key=cc_Systemic_lupus_erythematosus/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Systemic_lupus_eryth =1; end; else nomatch_cc_Systemic_lupus_eryth=0;
	set p_cc_Osteoporosis key=cc_Osteoporosis/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Osteoporosis =1; end; else nomatch_cc_Osteoporosis=0;
	set p_cc_Chronic_kidney_disea key=cc_Chronic_kidney_disease/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Chronic_kidney_disea =1; end; else nomatch_cc_Chronic_kidney_disea=0;
	set p_cc_Spina_bifida key=cc_Spina_bifida/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Spina_bifida =1; end; else nomatch_cc_Spina_bifida=0;
	set p_cc_Downs_syndrome key=cc_Downs_syndrome/unique; if _error_ ne 0 then do; _error_=0; nomatch_cc_Downs_syndrome =1; end; else nomatch_cc_Downs_syndrome=0;
	set p_mental_health key=mental_health/unique; if _error_ ne 0 then do; _error_=0; nomatch_mental_health =1; end; else nomatch_mental_health=0;
	set p_homeless key=homeless/unique; if _error_ ne 0 then do; _error_=0; nomatch_homeless =1; end; else nomatch_homeless=0;
	set p_post_transplant key=post_transplant/unique; if _error_ ne 0 then do; _error_=0; nomatch_post_transplant =1; end; else nomatch_post_transplant=0;
	set p_pacemaker key=pacemaker/unique; if _error_ ne 0 then do; _error_=0; nomatch_pacemaker =1; end; else nomatch_pacemaker=0;
	set p_ventilator key=ventilator/unique; if _error_ ne 0 then do; _error_=0; nomatch_ventilator =1; end; else nomatch_ventilator=0;
	set p_asthma key=asthma/unique; if _error_ ne 0 then do; _error_=0; nomatch_asthma =1; end; else nomatch_asthma=0;
	set p_malnutrition key=malnutrition/unique; if _error_ ne 0 then do; _error_=0; nomatch_malnutrition =1; end; else nomatch_malnutrition=0;
	set p_drug_use key=drug_use/unique; if _error_ ne 0 then do; _error_=0; nomatch_drug_use =1; end; else nomatch_drug_use=0;
	set p_dystocia key=dystocia/unique; if _error_ ne 0 then do; _error_=0; nomatch_dystocia =1; end; else nomatch_dystocia=0;
	set p_low_los_flag key=low_los_flag/unique; if _error_ ne 0 then do; _error_=0; nomatch_low_los_flag =1; end; else nomatch_low_los_flag=0;
	set p__pat_covid_flag key=_pat_covid_flag/unique; if _error_ ne 0 then do; _error_=0; nomatch__pat_covid_flag =1; end; else nomatch__pat_covid_flag=0;

/*	array	_p_intercept					_p_intercept: ;*/
/*	array	_p_agegroup						_p_agegroup: ;*/
/*	array	_p_an120mdc						_p_an120mdc_RA: ;*/
/*	array	_p_flag_ICUHours				_p_flag_ICUHours: ;*/
/*	array	_p_Charlson_Score				_p_Charlson_Score: ;*/
/*	array	_p_flag_AdmTransfer				_p_flag_AdmTransfer: ;*/
/*	array	_p_flag_emergency				_p_flag_emergency: ;*/
/*	array	_p_gender						_p_gender: ;*/
/*	array	_p_drg12_type					_p_drg12_type: ;*/
/**/
/*	array points					points01-points04  points06-points14;*/

%loop;


run;

data &output.;
	if _n_ eq 1 then set cPoints.p_intercept;
	set &output.0;

	set p_age15 				key=age_15g/unique;  				if _error_ ne 0 then do; _error_ = 0; nomatch_age15=1;				 _p_age_15g=0; 				end;
	set p_flag_foetal_distress 	key=flag_foetal_distress/unique;  	if _error_ ne 0 then do; _error_ = 0; nomatch_flag_foetal_distress=1;_p_flag_foetal_distress=0; end;
	set p_flag_PPOP 			key=flag_PPOP/unique; 				if _error_ ne 0 then do; _error_ = 0; nomatch_flag_PPOP=1; 			 _p_flag_PPOP=0; 			end;
	set p_flag_Primiparity 		key=flag_primiparity/unique;  		if _error_ ne 0 then do; _error_ = 0; nomatch_flag_primiparity=1;	 _p_flag_primiparity=0; 	end;
	set p_flag_instrument_use	key=flag_instrument_use/unique;  	if _error_ ne 0 then do; _error_ = 0; nomatch_flag_instrument_use=1; _p_flag_instrument_use=0; 	end;

	hac_points15 = min(100,max(0,round(sum(0	, 	_p_age_15g	
							,	_p_intercept15
							,	_p_flag_emergency15
							,	_p_flag_PPOP
							,	_p_flag_Primiparity
							,	_p_flag_foetal_distress
							,	_p_flag_instrument_use
							,   _p_dystocia15
						),1)));
	temp_idx = _n_;
	
/*	drop _p_:  ;*/

run;

proc datasets library=work nolist;
	delete
		p_age
		p_mdc
		p_flag_icuhours
/*	 	p_cc*/
		p_cc_acute_myo
		p_cc_cancer
		p_cc_cerebral_vasc
		p_cc_congestive_heart_failur
		p_cc_connective_tissue
		p_cc_dementia
		p_cc_diabetes
		p_cc_diabetes_comp
		p_cc_hiv
		p_cc_liver_disease
		p_cc_metastatic_cancer
		p_cc_paraplegia
		p_cc_peptic_ulcer
		p_cc_peripheral_vasc
		p_cc_pulmonary
		p_cc_renal_disease
		p_cc_severe_liver

	 	p_flag_admtransfer
	 	p_flag_emergency
	 	p_sex
	 	p_drg12_type
		p_age15 
		p_flag_instrument_use
		p_flag_PPOP
		p_flag_Primiparity
		p_flag_foetal_distress
 
		p_cc_Obesity
		p_cc_Cystic_fibrosis
		p_cc_Schizophrenia
		p_cc_Depression
		p_cc_Disorder_of_intellec
		p_cc_Parkinsons_disease
		p_cc_Multiple_sclerosis
		p_cc_Epilepsy
		p_cc_Cerebral_palsy
		p_cc_Ischaemic_heart_dise
		p_cc_Chronic_heart_failur
		p_cc_Hypertension
		p_cc_Emphysema_without_CO
		p_cc_COPD
		p_cc_Asthma_without_COPD
		p_cc_Bronchiectasis_witho
		p_cc_Chronic_respiratory_
		p_cc_Crohns_disease
		p_cc_Ulcerative_colitis
		p_cc_Chronic_liver_failur
		p_cc_Rheumatoid_arthritis
		p_cc_Arthritis_and_osteoa
		p_cc_Systemic_lupus_eryth
		p_cc_Osteoporosis
		p_cc_Chronic_kidney_disea
		p_cc_Spina_bifida
		p_cc_Downs_syndrome
		p_mental_health
		p_homeless
		p_post_transplant
		p_pacemaker
		p_ventilator
		p_asthma
		p_malnutrition
		p_drug_use
		p_dystocia
		p_low_los_flag
		p__pat_covid_flag

	 	&output.0;
quit;