226.GLOBAL EPILEPSY TREATMENT DATA ANALYSIS USING PROC OPTIONS | PROC FORMAT | PROC PRINT | PROC CONTENTS | PROC FREQ | PROC MEANS | PROC SGPLOT | PROC SQL | PROC EXPORT | PROC COMPARE

GLOBAL EPILEPSY TREATMENT DATA ANALYSIS USING PROC OPTIONS | PROC FORMAT | PROC PRINT | PROC CONTENTS | PROC FREQ | PROC MEANS | PROC SGPLOT | PROC SQL | PROC EXPORT | PROC COMPARE

 /*Worldwide epilepsy‑treatment dataset*/

1.Global program‑level OPTIONS (good style)

options nocenter nodate nonumber ls=132 ps=60

        varlenchk=NOWARN         /* ignore length “shrinking” */

        fmtsearch=(work);        /* look‑up custom formats    */


2.Creating the 25‑row dataset

data work.epil_world;

   length PatientID $8  Country $20 Region $15  EpilepsyType $25

          Sex $1 PrimaryDrug $15 SeizureControl $12 TreatmentRegimen $10 ;

   format DiagnosisDate TreatmentStart TreatmentEnd date9. ;


   infile datalines dsd truncover;

   input PatientID Country Region EpilepsyType $

         Age Sex $

         DiagnosisDate :date9.

         TreatmentStart :date9.

         TreatmentEnd   :date9.

         PrimaryDrug $ SeizureControl $ ;


   /*—— DERIVE LENGTH‑OF‑TREATMENT ——*/

   DurationMonths = intck('month', TreatmentStart, TreatmentEnd );


   /*—— DERIVE REGIMEN TYPE ——*/

   TreatmentRegimen = ifc(DurationMonths>24, 'Poly', 'Mono');


   label DurationMonths = 'Treatment Duration (Months)';

datalines;

P001,India,Asia,Focal,24,M,05JAN2022,15JAN2022,15JUL2024,Levetiracetam,Controlled

P002,USA,NorthAmerica,Generalized,32,F,20MAR2021,10APR2021,10JUN2023,Valproate,Partial

P003,Brazil,SouthAmerica,Focal_to_Bilateral,45,M,12DEC2019,01JAN2020,01JAN2024,Carbamazepine,Controlled

P004,UK,Europe,Generalized,29,F,15FEB2020,20FEB2020,20FEB2022,Topiramate,Controlled

P005,Japan,Asia,Focal,38,M,01AUG2018,15AUG2018,15FEB2025,Lacosamide,Uncontrolled

P006,Nigeria,Africa,Unknown,27,F,10OCT2022,20OCT2022,20APR2024,Phenytoin,Partial

P007,Germany,Europe,Focal,51,M,05MAY2017,20MAY2017,20MAY2020,Carbamazepine,Controlled

P008,Canada,NorthAmerica,Generalized,33,F,02JAN2023,05JAN2023,05JUL2024,Valproate,Partial

P009,Australia,Oceania,Focal,41,M,22JUL2020,01AUG2020,01FEB2023,Levetiracetam,Controlled

P010,India,Asia,Focal_to_Bilateral,16,F,12SEP2023,15SEP2023,15MAR2025,Oxcarbazepine,Uncontrolled

P011,France,Europe,Generalized,60,M,20APR2016,01MAY2016,01MAY2024,Valproate,Controlled

P012,Brazil,SouthAmerica,Focal,34,F,15NOV2020,20NOV2020,20NOV2023,Lacosamide,Partial

P013,USA,NorthAmerica,Unknown,22,M,01JAN2024,15JAN2024,15JUN2024,Levetiracetam,Uncontrolled

P014,Japan,Asia,Generalized,57,F,10JUN2019,20JUN2019,20DEC2023,Topiramate,Controlled

P015,India,Asia,Focal,30,M,05JUL2021,10JUL2021,10JAN2025,Carbamazepine,Partial

P016,Kenya,Africa,Focal,28,F,22FEB2022,01MAR2022,01MAR2024,Lacosamide,Controlled

P017,UK,Europe,Unknown,46,M,11NOV2020,20NOV2020,20NOV2023,Phenytoin,Partial

P018,USA,NorthAmerica,Focal_to_Bilateral,37,F,01APR2022,10APR2022,10OCT2024,Valproate,Controlled

P019,Australia,Oceania,Generalized,19,M,01JAN2023,05JAN2023,05JAN2025,Levetiracetam,Controlled

P020,India,Asia,Focal,52,F,15DEC2018,01JAN2019,01JAN2024,Carbamazepine,Uncontrolled

P021,Germany,Europe,Focal,48,M,20MAY2020,25MAY2020,25NOV2023,Lacosamide,Partial

P022,Canada,NorthAmerica,Generalized,31,F,02FEB2021,10FEB2021,10AUG2023,Topiramate,Controlled

P023,Nigeria,Africa,Focal_to_Bilateral,43,M,08AUG2019,15AUG2019,15FEB2023,Valproate,Partial

P024,Brazil,SouthAmerica,Generalized,26,F,10DEC2022,20DEC2022,20JUN2024,Phenytoin,Controlled

P025,Japan,Asia,Unknown,55,M,01SEP2020,10SEP2020,10MAR2023,Levetiracetam,Uncontrolled

;

run;

proc print;run;

Output:

Obs PatientID Country Region EpilepsyType Sex PrimaryDrug SeizureControl TreatmentRegimen DiagnosisDate TreatmentStart TreatmentEnd Age DurationMonths
1 P001 India Asia Focal M Levetiracetam Controlled Poly 05JAN2022 15JAN2022 15JUL2024 24 30
2 P002 USA NorthAmerica Generalized F Valproate Partial Poly 20MAR2021 10APR2021 10JUN2023 32 26
3 P003 Brazil SouthAmerica Focal_to_Bilateral M Carbamazepine Controlled Poly 12DEC2019 01JAN2020 01JAN2024 45 48
4 P004 UK Europe Generalized F Topiramate Controlled Mono 15FEB2020 20FEB2020 20FEB2022 29 24
5 P005 Japan Asia Focal M Lacosamide Uncontrolled Poly 01AUG2018 15AUG2018 15FEB2025 38 78
6 P006 Nigeria Africa Unknown F Phenytoin Partial Mono 10OCT2022 20OCT2022 20APR2024 27 18
7 P007 Germany Europe Focal M Carbamazepine Controlled Poly 05MAY2017 20MAY2017 20MAY2020 51 36
8 P008 Canada NorthAmerica Generalized F Valproate Partial Mono 02JAN2023 05JAN2023 05JUL2024 33 18
9 P009 Australia Oceania Focal M Levetiracetam Controlled Poly 22JUL2020 01AUG2020 01FEB2023 41 30
10 P010 India Asia Focal_to_Bilateral F Oxcarbazepine Uncontrolled Mono 12SEP2023 15SEP2023 15MAR2025 16 18
11 P011 France Europe Generalized M Valproate Controlled Poly 20APR2016 01MAY2016 01MAY2024 60 96
12 P012 Brazil SouthAmerica Focal F Lacosamide Partial Poly 15NOV2020 20NOV2020 20NOV2023 34 36
13 P013 USA NorthAmerica Unknown M Levetiracetam Uncontrolled Mono 01JAN2024 15JAN2024 15JUN2024 22 5
14 P014 Japan Asia Generalized F Topiramate Controlled Poly 10JUN2019 20JUN2019 20DEC2023 57 54
15 P015 India Asia Focal M Carbamazepine Partial Poly 05JUL2021 10JUL2021 10JAN2025 30 42
16 P016 Kenya Africa Focal F Lacosamide Controlled Mono 22FEB2022 01MAR2022 01MAR2024 28 24
17 P017 UK Europe Unknown M Phenytoin Partial Poly 11NOV2020 20NOV2020 20NOV2023 46 36
18 P018 USA NorthAmerica Focal_to_Bilateral F Valproate Controlled Poly 01APR2022 10APR2022 10OCT2024 37 30
19 P019 Australia Oceania Generalized M Levetiracetam Controlled Mono 01JAN2023 05JAN2023 05JAN2025 19 24
20 P020 India Asia Focal F Carbamazepine Uncontrolled Poly 15DEC2018 01JAN2019 01JAN2024 52 60
21 P021 Germany Europe Focal M Lacosamide Partial Poly 20MAY2020 25MAY2020 25NOV2023 48 42
22 P022 Canada NorthAmerica Generalized F Topiramate Controlled Poly 02FEB2021 10FEB2021 10AUG2023 31 30
23 P023 Nigeria Africa Focal_to_Bilateral M Valproate Partial Poly 08AUG2019 15AUG2019 15FEB2023 43 42
24 P024 Brazil SouthAmerica Generalized F Phenytoin Controlled Mono 10DEC2022 20DEC2022 20JUN2024 26 18
25 P025 Japan Asia Unknown M Levetiracetam Uncontrolled Poly 01SEP2020 10SEP2020 10MAR2023 55 30

3.First‑look exploration

3.1 What’s inside? (PROC CONTENTS)

proc contents data=work.epil_world varnum;

   title "Structure of EPIL_W (Worldwide Epilepsy Study)";

run;

Output:

Structure of EPIL_WORLD (Worldwide Epilepsy Study)

The CONTENTS Procedure

Data Set Name WORK.EPIL_WORLD Observations 25
Member Type DATA Variables 13
Engine V9 Indexes 0
Created 14/09/2015 00:06:14 Observation Length 152
Last Modified 14/09/2015 00:06:14 Deleted Observations 0
Protection   Compressed NO
Data Set Type   Sorted NO
Label      
Data Representation WINDOWS_64    
Encoding wlatin1 Western (Windows)    


Engine/Host Dependent Information
Data Set Page Size 65536
Number of Data Set Pages 1
First Data Page 1
Max Obs per Page 430
Obs in First Data Page 25
Number of Data Set Repairs 0
ExtendObsCounter YES
Filename C:\Users\Lenovo\AppData\Local\Temp\SAS Temporary Files\_TD10416_DESKTOP-QFAA4KV_\epil_world.sas7bdat
Release Created 9.0401M2
Host Created X64_8HOME


Variables in Creation Order
# Variable Type Len Format Label
1 PatientID Char 8    
2 Country Char 20    
3 Region Char 15    
4 EpilepsyType Char 25    
5 Sex Char 1    
6 PrimaryDrug Char 15    
7 SeizureControl Char 12    
8 TreatmentRegimen Char 10    
9 DiagnosisDate Num 8 DATE9.  
10 TreatmentStart Num 8 DATE9.  
11 TreatmentEnd Num 8 DATE9.  
12 Age Num 8    
13 DurationMonths Num 8   Treatment Duration (Months)


3.2 Raw peek (PROC PRINT with WHERE)

proc print data=work.epil_world(obs=10);

   title "First 10 Records – Sanity Check";

   where Country in ('India','USA');

run;

Output:

First 10 Records – Sanity Check

Obs PatientID Country Region EpilepsyType Sex PrimaryDrug SeizureControl TreatmentRegimen DiagnosisDate TreatmentStart TreatmentEnd Age DurationMonths
1 P001 India Asia Focal M Levetiracetam Controlled Poly 05JAN2022 15JAN2022 15JUL2024 24 30
2 P002 USA NorthAmerica Generalized F Valproate Partial Poly 20MAR2021 10APR2021 10JUN2023 32 26
10 P010 India Asia Focal_to_Bilateral F Oxcarbazepine Uncontrolled Mono 12SEP2023 15SEP2023 15MAR2025 16 18
13 P013 USA NorthAmerica Unknown M Levetiracetam Uncontrolled Mono 01JAN2024 15JAN2024 15JUN2024 22 5
15 P015 India Asia Focal M Carbamazepine Partial Poly 05JUL2021 10JUL2021 10JAN2025 30 42
18 P018 USA NorthAmerica Focal_to_Bilateral F Valproate Controlled Poly 01APR2022 10APR2022 10OCT2024 37 30
20 P020 India Asia Focal F Carbamazepine Uncontrolled Poly 15DEC2018 01JAN2019 01JAN2024 52 60

4.Descriptive statistics

4.1 Demographics by epilepsy type (PROC FREQ)

proc freq data=work.epil_world order=freq;

   table EpilepsyType*Sex / nocol nopercent nocum;

   title "Sex Distribution by Epilepsy Classification";

run;

Output:

Sex Distribution by Epilepsy Classification

The FREQ Procedure

Frequency
Row Pct
Table of EpilepsyType by Sex
EpilepsyType Sex
M F Total
Focal
6
66.67
3
33.33
9
 
Generalized
2
25.00
6
75.00
8
 
Focal_to_Bilateral
2
50.00
2
50.00
4
 
Unknown
3
75.00
1
25.00
4
 
Total
13
12
25


4.2 Treatment length distribution (PROC MEANS)

proc means data=work.epil_world n mean median min max maxdec=1;

   class EpilepsyType;

   var DurationMonths Age;

   title "Duration & Age, Broken Down by Epilepsy Class";

run;

Output:

Duration & Age, Broken Down by Epilepsy Class

The MEANS Procedure

EpilepsyType N Obs Variable Label N Mean Median Minimum Maximum
Focal 9
DurationMonths
Age
Treatment Duration (Months)
 
9
9
42.0
38.4
36.0
38.0
24.0
24.0
78.0
52.0
Focal_to_Bilateral 4
DurationMonths
Age
Treatment Duration (Months)
 
4
4
34.5
35.3
36.0
40.0
18.0
16.0
48.0
45.0
Generalized 8
DurationMonths
Age
Treatment Duration (Months)
 
8
8
36.3
35.9
25.0
31.5
18.0
19.0
96.0
60.0
Unknown 4
DurationMonths
Age
Treatment Duration (Months)
 
4
4
22.3
37.5
24.0
36.5
5.0
22.0
36.0
55.0

4.3 Quick plot (PROC SGPLOT with summary function)

proc sgplot data=work.epil_world;

   vbox DurationMonths / category=Region;

   title "Boxplot: Months on Treatment by Global Region";

run;

Log:

NOTE: PROCEDURE SGPLOT used (Total process time):

      real time           3.32 seconds

      cpu time            0.56 seconds


NOTE: Listing image output written to SGPlot1.png.

NOTE: There were 25 observations read from the data set WORK.EPIL_WORLD.


5.Custom formats to declutter outputs

proc format;

   value $reg 'NorthAmerica' = 'N. America'

              'SouthAmerica' = 'S. America'

              'Oceania'      = 'Oce'

              other          = 'OTHER';

run;


proc freq data=work.epil_world;

   format Region $reg.;

   tables Region*SeizureControl / norow nocol nopercent;

   title "Outcome vs Region Using User Format";

run;

Output:

Outcome vs Region Using User Format

The FREQ Procedure

Frequency
Table of Region by SeizureControl
Region SeizureControl
Controlled Partial Uncontrolled Total
OTHER
6
5
4
15
N. America
2
2
1
5
Oce
2
0
0
2
S. America
2
1
0
3
Total
12
8
5
25

6.Analytic SQL snippets

proc sql;

   title "Mean Treatment Duration by Country & Control Status";

   select Country,

          SeizureControl,

          count(*)               as N_Patients,

          mean(DurationMonths)   as Avg_Months format=5.1

   from   work.epil_world

   group  by Country, SeizureControl

   having calculated Avg_Months > 18

   order  by Avg_Months desc;

quit;

Output:

Mean Treatment Duration by Country & Control Status

Country SeizureControl N_Patients Avg_Months
France Controlled 1 96.0
Japan Uncontrolled 2 54.0
Japan Controlled 1 54.0
Germany Partial 1 42.0
India Partial 1 42.0
India Uncontrolled 2 39.0
UK Partial 1 36.0
Germany Controlled 1 36.0
Brazil Partial 1 36.0
Brazil Controlled 2 33.0
Nigeria Partial 2 30.0
Canada Controlled 1 30.0
India Controlled 1 30.0
USA Controlled 1 30.0
Australia Controlled 2 27.0
USA Partial 1 26.0
UK Controlled 1 24.0
Kenya Controlled 1 24.0


7.Reusable macro: %SummaryBy

%macro SummaryBy(data=, class=, statvar=, outfile=);

   %local i n var;

   %let n=%sysfunc(countw(&class));


   %do i=1 %to &n;

      %let var=%scan(&class,&i);


      title "===&var Summary===";

      proc means data=&data n mean median maxdec=1;

         class &var;

         var &statvar;

      run;


      proc freq data=&data;

         tables &var / nocum nopercent;

      run;


      /*—— optional export ——*/

      %if %length(&outfile) %then %do;

         proc export data=&data(keep=&var &statvar)

             outfile="&outfile._&var..csv"

             dbms=csv replace;

         run;

      %end;

   %end;

%mend SummaryBy;


%SummaryBy(data=work.epil_world,

           class=Region EpilepsyType TreatmentRegimen,

           statvar=DurationMonths,

           outfile=%sysfunc(pathname(work))/epil_out);

Output:

===Region Summary===

The MEANS Procedure

Analysis Variable : DurationMonths Treatment Duration (Months)
Region N Obs N Mean Median
Africa 3 3 28.0 24.0
Asia 7 7 44.6 42.0
Europe 5 5 46.8 36.0
NorthAmerica 5 5 21.8 26.0
Oceania 2 2 27.0 27.0
SouthAmerica 3 3 34.0 36.0


===Region Summary===

The FREQ Procedure

Region Frequency
Africa 3
Asia 7
Europe 5
NorthAmerica 5
Oceania 2
SouthAmerica 3

===EpilepsyType Summary===

The MEANS Procedure

Analysis Variable : DurationMonths Treatment Duration (Months)
EpilepsyType N Obs N Mean Median
Focal 9 9 42.0 36.0
Focal_to_Bilateral 4 4 34.5 36.0
Generalized 8 8 36.3 25.0
Unknown 4 4 22.3 24.0

===EpilepsyType Summary===

The FREQ Procedure

EpilepsyType Frequency
Focal 9
Focal_to_Bilateral 4
Generalized 8
Unknown 4

===TreatmentRegimen Summary===

The MEANS Procedure

Analysis Variable : DurationMonths Treatment Duration (Months)
TreatmentRegimen N Obs N Mean Median
Mono 8 8 18.6 18.0
Poly 17 17 43.9 36.0

===TreatmentRegimen Summary===

The FREQ Procedure

TreatmentRegimen Frequency
Mono 8
Poly 17

8.Quality‑control snapshot

Compare derived vs re‑computed (PROC COMPARE)

data qc;

   set work.epil_world;

   RecalcMonths = intck('month', TreatmentStart, TreatmentEnd);

run;

proc print;run;

Obs PatientID Country Region EpilepsyType Sex PrimaryDrug SeizureControl TreatmentRegimen DiagnosisDate TreatmentStart TreatmentEnd Age DurationMonths RecalcMonths
1 P001 India Asia Focal M Levetiracetam Controlled Poly 05JAN2022 15JAN2022 15JUL2024 24 30 30
2 P002 USA NorthAmerica Generalized F Valproate Partial Poly 20MAR2021 10APR2021 10JUN2023 32 26 26
3 P003 Brazil SouthAmerica Focal_to_Bilateral M Carbamazepine Controlled Poly 12DEC2019 01JAN2020 01JAN2024 45 48 48
4 P004 UK Europe Generalized F Topiramate Controlled Mono 15FEB2020 20FEB2020 20FEB2022 29 24 24
5 P005 Japan Asia Focal M Lacosamide Uncontrolled Poly 01AUG2018 15AUG2018 15FEB2025 38 78 78
6 P006 Nigeria Africa Unknown F Phenytoin Partial Mono 10OCT2022 20OCT2022 20APR2024 27 18 18
7 P007 Germany Europe Focal M Carbamazepine Controlled Poly 05MAY2017 20MAY2017 20MAY2020 51 36 36
8 P008 Canada NorthAmerica Generalized F Valproate Partial Mono 02JAN2023 05JAN2023 05JUL2024 33 18 18
9 P009 Australia Oceania Focal M Levetiracetam Controlled Poly 22JUL2020 01AUG2020 01FEB2023 41 30 30
10 P010 India Asia Focal_to_Bilateral F Oxcarbazepine Uncontrolled Mono 12SEP2023 15SEP2023 15MAR2025 16 18 18
11 P011 France Europe Generalized M Valproate Controlled Poly 20APR2016 01MAY2016 01MAY2024 60 96 96
12 P012 Brazil SouthAmerica Focal F Lacosamide Partial Poly 15NOV2020 20NOV2020 20NOV2023 34 36 36
13 P013 USA NorthAmerica Unknown M Levetiracetam Uncontrolled Mono 01JAN2024 15JAN2024 15JUN2024 22 5 5
14 P014 Japan Asia Generalized F Topiramate Controlled Poly 10JUN2019 20JUN2019 20DEC2023 57 54 54
15 P015 India Asia Focal M Carbamazepine Partial Poly 05JUL2021 10JUL2021 10JAN2025 30 42 42
16 P016 Kenya Africa Focal F Lacosamide Controlled Mono 22FEB2022 01MAR2022 01MAR2024 28 24 24
17 P017 UK Europe Unknown M Phenytoin Partial Poly 11NOV2020 20NOV2020 20NOV2023 46 36 36
18 P018 USA NorthAmerica Focal_to_Bilateral F Valproate Controlled Poly 01APR2022 10APR2022 10OCT2024 37 30 30
19 P019 Australia Oceania Generalized M Levetiracetam Controlled Mono 01JAN2023 05JAN2023 05JAN2025 19 24 24
20 P020 India Asia Focal F Carbamazepine Uncontrolled Poly 15DEC2018 01JAN2019 01JAN2024 52 60 60
21 P021 Germany Europe Focal M Lacosamide Partial Poly 20MAY2020 25MAY2020 25NOV2023 48 42 42
22 P022 Canada NorthAmerica Generalized F Topiramate Controlled Poly 02FEB2021 10FEB2021 10AUG2023 31 30 30
23 P023 Nigeria Africa Focal_to_Bilateral M Valproate Partial Poly 08AUG2019 15AUG2019 15FEB2023 43 42 42
24 P024 Brazil SouthAmerica Generalized F Phenytoin Controlled Mono 10DEC2022 20DEC2022 20JUN2024 26 18 18
25 P025 Japan Asia Unknown M Levetiracetam Uncontrolled Poly 01SEP2020 10SEP2020 10MAR2023 55 30 30

proc compare base=qc(rename=(DurationMonths=Dur1))

             compare=qc(rename=(RecalcMonths=Dur2))

             criterion=0.0001 /* tolerance */

             out=diff(where=(difference ne 0));

   id PatientID;

   var Dur1;

   with Dur2;

   title "QC: Derived Duration vs Recalc";

run;

Output:

QC: Derived Duration vs Recalc

The COMPARE Procedure                                                                                                               
Comparison of WORK.QC with WORK.QC                                                                                                  
(Method=RELATIVE(2.22E-10), Criterion=0.0001)                                                                                       
                                                                                                                                    
Data Set Summary                                                                                                                    
                                                                                                                                    
Dataset           Created          Modified  NVar    NObs                                                                           
                                                                                                                                    
WORK.QC  14SEP15:00:35:14  14SEP15:00:35:14    14      25                                                                           
WORK.QC  14SEP15:00:35:14  14SEP15:00:35:14    14      25                                                                           
                                                                                                                                    
                                                                                                                                    
Variables Summary                                                                                                                   
                                                                                                                                    
Number of Variables in Common: 12.                                                                                                  
Number of Variables in WORK.QC but not in WORK.QC: 2.                                                                               
Number of Variables in WORK.QC but not in WORK.QC: 2.                                                                               
Number of ID Variables: 1.                                                                                                          
Number of VAR Statement Variables: 1.                                                                                               
Number of WITH Statement Variables: 1.

To Visit My Previous Sas Questions Datasets:Click Here
To Visit My Previous Home Energy Consumption Dataset:Click Here
To Visit My Previous Wildlife Migration Dataset:Click Here
To Visit My Previous Endangered Species Dataset:Click Here


-->PRACTICE AND COMMENT YOUR OUTPUT: 
--->PLEASE FOLLOW OUR BLOG FOR MORE UPDATES.

PLEASE FOLLOW OUR TELEGRAM CHANNEL CLICK HERE

PLEASE FOLLOW OUR FACEBOOK PAGE  CLICK HERE

PLEASE FOLLOW OUR INSTAGRAM PAGE CLICK HERE

Comments