Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 48.02 KB | None | 0 0
  1. /*  Temporary JORA Tables */
  2.  
  3. /*Create library
  4. LIBNAME shredstg BASE "\\Aofrontex.local\frontex-shared\Restricted Area\Operations Division\RAU\RAU Work\FRAN\SAS\sasdata\SAS_DB" ;
  5. LIBNAME JORAOUT ACCESS "\\Aofrontex.local\frontex-shared\Restricted Area\Operations Division\RAU\RAU Work\FRAN\SAS\SASdata\Accessdata\JoraData.accdb" ;
  6. */
  7.  
  8. /*%macro Jorali%put nk;
  9. %IF "&SysuserId." EQ "albertinellia"
  10. %then LIBNAME JORARAUW ACCESS "\\Aofrontex.local\frontex-shared\Restricted Area\Operations Division\RAU\RAU Work\FRAN\SAS\SASdata\Accessdata\JoraLinkTony.accdb" ;
  11. %IF "&SysuserId." EQ "bulea"
  12. %then LIBNAME JORARAUW ACCESS "\\Aofrontex.local\frontex-shared\Restricted Area\Operations Division\RAU\RAU Work\FRAN\SAS\SASdata\Accessdata\JoraLinkAnca.accdb" ;
  13. %IF "&SysuserId." EQ "doweyd"
  14. %then LIBNAME JORARAUW ACCESS "\\Aofrontex.local\frontex-shared\Restricted Area\Operations Division\RAU\RAU Work\FRAN\SAS\SASdata\Accessdata\JORARAUlinkAll.accdb" ;
  15. %mend;
  16.  
  17. %Joralink;*/
  18.  
  19.  
  20. ;
  21. proc format;
  22.     value fmt_joraIncStatus
  23.     1 = "Pending"
  24.     2 = "For LCC Verification"
  25.     3 = "For ICC Verification"
  26.     4 = "For FSC Verification"
  27.     5 = "Accepted"
  28.     other = "Unknown"
  29.     ;
  30. run;
  31. data work.fmt_country_short;
  32.     set jorarau.Country(keep=id ShortName);
  33.     rename ID=Start ShortName=Label;
  34.     fmtname='fmt_country_short';
  35. run;
  36. proc format cntlin=work.fmt_country_short;
  37. run;
  38. data work.fmt_country_long;
  39.     set jorarau.Country(keep=id LongName);
  40.     rename ID=Start LongName=Label;
  41.     fmtname='fmt_country_long';
  42. run;
  43. proc format cntlin=work.fmt_country_long;
  44. run;
  45. data work.fmt_joraDict;
  46.     set jorarau.Dictionary(keep=id Name);
  47.     rename ID=Start Name=Label;
  48.     fmtname='fmt_joraDict';
  49. run;
  50. proc format cntlin=work.fmt_joraDict;
  51. run;
  52. proc sql;
  53.     create table test_ctr as
  54.     select d.id as start, c.ShortName, c.LongName
  55.     from jorarau.dictionary as d, jorarau.country as c
  56.     where d.CountryId = c.Id
  57.     ;
  58. quit;
  59. proc sql;
  60.     create table test_bs as
  61.     select d.id as Start, c.ShortName, c.LongName
  62.     from jorarau.dictionary as d, jorarau.country as c
  63.     where d.BorderSectionId = c.Id
  64.     ;
  65. quit;
  66. data test_ctr_short;
  67.     set test_ctr(keep=start ShortName) end=koniec;
  68.     rename ShortName=Label;
  69.     fmtname="fmt_bs_p1_short";
  70.     if koniec then do;
  71.         HLO="O";
  72.         Start = .;
  73.         ShortName="";
  74.         output;
  75.     end;
  76. run;
  77. data test_ctr_long;
  78.     set test_ctr(keep=start LongName) end=koniec;
  79.     rename LongName=Label;
  80.     fmtname="fmt_bs_p1_long";
  81.     if koniec then do;
  82.         HLO="O";
  83.         Start = .;
  84.         LongName="";
  85.         output;
  86.     end;
  87. run;
  88. proc format cntlin=test_ctr_short;
  89. run;
  90. proc format cntlin=test_ctr_long;
  91. run;
  92. data test_bs_short;
  93.     set test_bs(keep=start ShortName) end=koniec;
  94.     rename ShortName=Label;
  95.     fmtname="fmt_bs_p2_short";
  96.     if koniec then do;
  97.         HLO="O";
  98.         Start = .;
  99.         ShortName="";
  100.         output;
  101.     end;
  102. run;
  103. data test_bs_long;
  104.     set test_bs(keep=start LongName) end=koniec;
  105.     length HLO $1.;
  106.     rename LongName=Label;
  107.     fmtname="fmt_bs_p2_long";
  108.     output;
  109.     if koniec then do;
  110.         HLO="O";
  111.         Start = .;
  112.         LongName="";
  113.         output;
  114.     end;
  115. run;
  116. proc format cntlin=test_bs_short;
  117. run;
  118. proc format cntlin=test_bs_long;
  119. run;
  120.  
  121.  
  122.  
  123. %macro FormatValue(src, fmt);
  124.     case when missing(&src.) eq 0 then strip(put(&src., &fmt..)) else "" end
  125. %mend;
  126. %macro DelTbl(lib, prf);
  127.     proc datasets lib=&lib. nolist nowarn;
  128.         delete &prf.:;
  129.     quit;
  130. %mend;
  131.  
  132.  
  133.  
  134.  
  135.  
  136. /* Drop tables from Access database */
  137. options fmtsearch=(work);
  138. options compress=yes;
  139.  
  140.      /*JORA_nat format*/
  141.      DATA WORK._EG_CFMT;
  142.          LENGTH label $ 44;
  143.          SET JORARAU.Country (KEEP=ID longname RENAME=(ID=start longname=label));
  144.          RETAIN fmtname "Jora_Nat" type "N";
  145.          end=start;
  146.      RUN;
  147.  
  148.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  149.      RUN;
  150.  
  151.      PROC SQL;
  152.          DROP TABLE WORK._EG_CFMT, work.location;
  153.      QUIT;
  154.  
  155.      /*Format from label to isocode*/
  156.       DATA WORK._EG_CFMT;
  157.          LENGTH label $ 44;
  158.          SET JORARAU.Country (KEEP=longname shortname RENAME=(longname=start shortname=label));
  159.          RETAIN fmtname "LabelToIso" type "C";
  160.          end=start;
  161.      RUN;
  162.  
  163.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  164.      RUN;
  165.  
  166.      PROC SQL;
  167.          DROP TABLE WORK._EG_CFMT, work.location;
  168.      QUIT;
  169.  
  170. DATA WORK._EG_CFMT;
  171.          LENGTH label $ 40;
  172.          SET JORARAU.DICTIONARY (KEEP=Id name RENAME=(Id=start name=label));
  173.          RETAIN fmtname "DICTIONARY" type "N";
  174.          end=start;
  175.      RUN;
  176.  
  177.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  178.      RUN;
  179.  
  180.  
  181.      PROC SQL;
  182.          DROP TABLE WORK._EG_CFMT;
  183.      QUIT;
  184.  
  185.      /*JORA_natcode format*/
  186.      DATA WORK._EG_CFMT;
  187.          LENGTH label $ 44;
  188.          SET JORARAU.Country (KEEP=ID shortname RENAME=(ID=start shortname=label));
  189.          RETAIN fmtname "Jora_isocode" /*type "T"*/;
  190.          end=start;
  191.      RUN;
  192.  
  193.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  194.      RUN;
  195.  
  196.      PROC SQL;
  197.          DROP TABLE WORK._EG_CFMT, work.location;
  198.      QUIT;
  199.  
  200.  
  201.      DATA WORK._EG_CFMT;
  202.          LENGTH label $ 32;
  203.          SET JORARAU.systemUser (KEEP=Id Email RENAME=(Id=start Email=label));
  204.          RETAIN fmtname "SYS_USER" type "N";
  205.          end=start;
  206.      RUN;
  207.  
  208.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  209.      RUN;
  210.  
  211.  
  212.      PROC SQL;
  213.          DROP TABLE WORK._EG_CFMT;
  214.      QUIT;
  215.  
  216.      DATA WORK._EG_CFMT;
  217.          LENGTH label $ 32;
  218.          SET JORARAU.LOCATION (KEEP=Id Name RENAME=(Id=start Name=label));
  219.          RETAIN fmtname "JORA_OP_AREA" type "N";
  220.          end=start;
  221.      RUN;
  222.  
  223.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  224.      RUN;
  225.  
  226.      PROC SQL;
  227.          DROP TABLE WORK._EG_CFMT;
  228.      QUIT;
  229.  
  230.      /*Preparation of tmp dataset location in order to preapre further formats*/
  231.  
  232.      data location(keep=Id name parentname bordersection memberstate keybordersection latitude longitude reportinglocationid);
  233.      set JORARAU.location;
  234.      length parentname $30 bordersection $30 memberstate $30 keybordersection $50;
  235.      ParentName=put(parentlocationid,JORA_OP_AREA.);
  236.      bordersection=put(bordersectionid,Jora_Nat.);
  237.      memberstate=put(memberstateid,Jora_Nat.);
  238.      if (trim(bordersection) NE " ")
  239.      then Keybordersection=trim(memberstate)||"-"||trim(bordersection);
  240.      run;
  241.  
  242.  
  243.  
  244.      /*Parent_loc format*/
  245.      DATA WORK._EG_CFMT;
  246.          LENGTH label $ 40;
  247.          SET WORK.LOCATION (KEEP=Id parentname RENAME=(Id=start parentname=label));
  248.          RETAIN fmtname "JORA_LOC_PARENT" type "N";
  249.      
  250.          end=start;
  251.      RUN;
  252.  
  253.  
  254.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  255.      RUN;
  256.  
  257.      PROC SQL;
  258.          DROP TABLE WORK._EG_CFMT;
  259.      QUIT;
  260.  
  261.      
  262.      /* JORA_LOC_BS format */
  263.      DATA WORK._EG_CFMT;
  264.          LENGTH label $ 40;
  265.          SET WORK.LOCATION (KEEP=Id bordersection RENAME=(Id=start bordersection=label));
  266.          RETAIN fmtname "JORA_LOC_BS" type "N";
  267.          end=start;
  268.      RUN;
  269.  
  270.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  271.      RUN;
  272.  
  273.      
  274.      PROC SQL;
  275.          DROP TABLE WORK._EG_CFMT;
  276.      QUIT;
  277.  
  278.      
  279.      /*JORA_LOC_MS format*/
  280.      DATA WORK._EG_CFMT;
  281.          LENGTH label $ 40;
  282.          SET WORK.LOCATION (KEEP=Id memberstate RENAME=(Id=start memberstate=label));
  283.          RETAIN fmtname "JORA_LOC_MS" type "N";
  284.          end=start;
  285.      RUN;
  286.  
  287.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  288.      RUN;
  289.  
  290.      
  291.      PROC SQL;
  292.          DROP TABLE WORK._EG_CFMT;
  293.      QUIT;
  294.  
  295.      /*JORA_LOC_KBS format*/
  296.      DATA WORK._EG_CFMT;
  297.          LENGTH label $ 50;
  298.          SET WORK.LOCATION (KEEP=Id keybordersection RENAME=(Id=start keybordersection=label));
  299.          RETAIN fmtname "JORA_LOC_KBS" type "N";
  300.          end=start;
  301.      RUN;
  302.  
  303.      PROC FORMAT library=work CNTLIN=WORK._EG_CFMT;
  304.      RUN;
  305.  
  306.      PROC SQL;
  307.          DROP TABLE WORK._EG_CFMT;
  308.      QUIT;
  309.  
  310.  
  311.  
  312.      /**************************/
  313.      /*End of format definition*/
  314.      /*************************/
  315.      PROC SQL;*/
  316.         CREATE TABLE work.JORA_NAT_PrimaryOperation AS
  317.         SELECT t4.Name as OperationName,
  318.               put(t4.operationalScopeid,DICTIONARY.) as OperationalScope,
  319.               "Primary" as OperationReporting,         
  320.               put(t4.operationsectortypeid,DICTIONARY.) as SectorType,     
  321.               put(t1.OperationalAreaId,JORA_OP_AREA.) as OperationalArea,
  322.               put(t1.OperationalAreaId,JORA_LOC_PARENT.) as ParentLocation,
  323.               put(t1.OperationalAreaId,JORA_LOC_BS.) as Bordersection,
  324.               put(t1.OperationalAreaId,JORA_LOC_MS.) as MemberState,
  325.               put(t1.OperationalAreaId,JORA_LOC_KBS.) as KeyBorderSection,
  326.               t1.statusid, /*Status of the incident
  327.               put(t1.approverID,Sys_user.) as ApproverID,  
  328.               t1.DetectedBy,    
  329.               t1.InterceptionDate,
  330.               put(datepart(t1.InterceptionDate),YYMMDD10.) as InterceptionDate_day,
  331.               put(timepart(t1.InterceptionDate),time8.) as InterceptionDate_time,
  332.               put(datepart(t1.InterceptionDate),YYMM.) as Interceptiondate_YYYYMM,
  333.               t1.detectiontime,
  334.               put(datepart(t1.detectiontime),YYMMDD10.) as detectiontime_day,
  335.               put(timepart(t1.detectiontime),time8.) as detectiontime_time,
  336.               put(datepart(t1.detectiontime),YYMM.) as detectiontime_YYYYMM,
  337.               t1.InterceptionPlaceComments,
  338.               t1.InterceptedBy,    
  339.               t1.CreateDate,
  340.               put(datepart(t1.CreateDate),YYMMDD10.) as CreateDate_day,
  341.               put(timepart(t1.CreateDate),time8.) as CreateDate_time,
  342.               put(datepart(t1.CreateDate),YYMM.) as Createdate_YYYYMM,
  343.               put(year(datepart(t1.CreateDate)),4.)||"Wk"||put(week(datepart(t1.CreateDate),'v'),2.) as Createdate_YYYYWK,
  344.               t1.Latitude,
  345.               t1.LatitudeDetection,    
  346.               t1.Longitude,
  347.               t1.LongitudeDetection,    
  348.               t1.TimeOfDeparture,
  349.               t1.Disembarkation,
  350.               t1.PlaceOfDeparture,
  351.               t1.Comments,
  352.               t1.DeathCases,
  353.               t1.IncidentNumber,
  354.               t1.MarketValue,
  355.               t1.MigrantsDeterred,
  356.               t1.TransportMeansNumber,
  357.               t1.SearchAndRescueInvolved,
  358.               t1.SmugglingOfNumber,
  359.               t1.make,
  360.               t1.model,
  361.               put(t1.platenationalityid,Jora_nat.) as PlateNationality,
  362.               put(t1.drivernationalityid,Jora_nat.) as DriverNationality,
  363.               put(t1.countryofdepartureID,Jora_nat.) as CountryOfDeparture,
  364.               put(t1.countryofdestinationID,Jora_nat.) as CountryOfDestination,
  365.               put(t1.ReferenceId,DICTIONARY.) as RefOperationalArea,
  366.               put(t1.IncidentTypeId,DICTIONARY.) as IncidentType,
  367.               put(t1.BoatDestroyedById,DICTIONARY.) as BoatDestroyedBy,
  368.               put(t1.SmugglingOfId,DICTIONARY.) as SmugglingOf,
  369.               put(t1.PlaceOfInterceptionId ,DICTIONARY.) as PlaceOfInterception,
  370.               put(t1.ZoneId ,DICTIONARY.) As Zone,
  371.               put(t1.DestinationMethodOfTransportId ,DICTIONARY.) as TransportType,
  372.               t3.nationalityclaimedID,
  373.               t3.nationalitypresumedID,
  374.               t3.nationalityConfirmedID,
  375.               put(t3.RefusalReasonId ,DICTIONARY.) as Nat_RefusalReason,
  376.               put(t3.PersonRoleId ,DICTIONARY.) as Nat_PersonRole,  
  377.               t3.NumberOfPersons,
  378.               t3.NumberOfAdultsMale,
  379.               t3.NumberOfMinorFemale,
  380.               t3.NumberOfAdultsFemale,
  381.               t3.NumberOfMinorMale,
  382.               count(incidentnumber) as NbRecord
  383.           FROM JORARAU.Incident t1
  384.           INNER JOIN JORARAU.NationalityInformation t3 ON (t1.Id = t3.incidentId)
  385.           INNER JOIN JORARAU.Operation t4 ON (t1.OperationId = t4.Id)
  386.           Where t1.isdeleted NE 1 and t1.isaccepted=1
  387.           group by OperationName, IncidentNumber
  388.         ORDER BY t1.InterceptionDate DESC;/*
  389.  
  390. CREATE TABLE work.JORA_NAT_SecondaryOperation AS
  391.         SELECT t4.Name as OperationName,
  392.               put(t4.operationalScopeid,DICTIONARY.) as OperationalScope,
  393.               "Secondary" as OperationReporting,   
  394.               put(t4.operationsectortypeid,DICTIONARY.) as SectorType,     
  395.               put(t1.OperationalAreaId,JORA_OP_AREA.) as OperationalArea,
  396.               put(t1.OperationalAreaId,JORA_LOC_PARENT.) as ParentLocation,
  397.               put(t1.OperationalAreaId,JORA_LOC_BS.) as Bordersection,
  398.               put(t1.OperationalAreaId,JORA_LOC_MS.) as MemberState,
  399.               put(t1.OperationalAreaId,JORA_LOC_KBS.) as KeyBorderSection,
  400.               t1.statusid, Status of the incident
  401.               put(t1.approverID,Sys_user.) as ApproverID,  
  402.               t1.DetectedBy,    
  403.               t1.InterceptionDate,
  404.               put(datepart(t1.InterceptionDate),YYMMDD10.) as InterceptionDate_day,
  405.               put(timepart(t1.InterceptionDate),time8.) as InterceptionDate_time,
  406.               put(datepart(t1.InterceptionDate),YYMM.) as Interceptiondate_YYYYMM,
  407.               t1.detectiontime,
  408.               put(datepart(t1.detectiontime),YYMMDD10.) as detectiontime_day,
  409.               put(timepart(t1.detectiontime),time8.) as detectiontime_time,
  410.               put(datepart(t1.detectiontime),YYMM.) as detectiontime_YYYYMM,
  411.               t1.InterceptionPlaceComments,
  412.               t1.InterceptedBy,    
  413.               t1.CreateDate,
  414.               put(datepart(t1.CreateDate),YYMMDD10.) as CreateDate_day,
  415.               put(timepart(t1.CreateDate),time8.) as CreateDate_time,
  416.               put(datepart(t1.CreateDate),YYMM.) as Createdate_YYYYMM,
  417.               put(year(datepart(t1.CreateDate)),4.)||"Wk"||put(week(datepart(t1.CreateDate),'v'),2.) as Createdate_YYYYWK,
  418.               t1.Latitude,
  419.               t1.LatitudeDetection,    
  420.               t1.Longitude,
  421.               t1.LongitudeDetection,    
  422.               t1.TimeOfDeparture,
  423.               t1.Disembarkation,
  424.               t1.PlaceOfDeparture,
  425.               t1.Comments,
  426.               t1.DeathCases,
  427.               t1.IncidentNumber,
  428.               t1.MarketValue,
  429.               t1.MigrantsDeterred,
  430.               t1.TransportMeansNumber,
  431.               t1.SearchAndRescueInvolved,
  432.               t1.SmugglingOfNumber,
  433.               t1.make,
  434.               t1.model,
  435.               put(t1.platenationalityid,Jora_nat.) as PlateNationality,
  436.               put(t1.drivernationalityid,Jora_nat.) as DriverNationality,
  437.               put(t1.countryofdepartureID,Jora_nat.) as CountryOfDeparture,
  438.               put(t1.countryofdestinationID,Jora_nat.) as CountryOfDestination,
  439.               put(t1.ReferenceId,DICTIONARY.) as RefOperationalArea,
  440.               put(t1.IncidentTypeId,DICTIONARY.) as IncidentType,
  441.               put(t1.BoatDestroyedById,DICTIONARY.) as BoatDestroyedBy,
  442.               put(t1.SmugglingOfId,DICTIONARY.) as SmugglingOf,
  443.               put(t1.PlaceOfInterceptionId ,DICTIONARY.) as PlaceOfInterception,
  444.               put(t1.ZoneId ,DICTIONARY.) As Zone,
  445.               put(t1.DestinationMethodOfTransportId ,DICTIONARY.) as TransportType,
  446.               t3.nationalityclaimedID,
  447.               t3.nationalitypresumedID,
  448.               t3.nationalityConfirmedID,
  449.               put(t3.RefusalReasonId ,DICTIONARY.) as Nat_RefusalReason,
  450.               put(t3.PersonRoleId ,DICTIONARY.) as Nat_PersonRole,  
  451.               t3.NumberOfPersons,
  452.               t3.NumberOfAdultsMale,
  453.               t3.NumberOfMinorFemale,
  454.               t3.NumberOfAdultsFemale,
  455.               t3.NumberOfMinorMale,
  456.               count(incidentnumber) as NbRecord
  457.           FROM JORARAU.Incident t1
  458.           INNER JOIN JORARAU.NationalityInformation t3 ON (t1.Id = t3.incidentId)
  459.           INNER JOIN JORARAU.IncidentRelatedOperation t2 ON (t1.Id = t2.IncidentId)
  460.           INNER JOIN JORARAU.Operation t4 ON (t2.OperationId = t4.Id)
  461.           Where t1.isdeleted NE 1  and t1.isaccepted=1
  462.           group by OperationName, IncidentNumber
  463.         ORDER BY t1.InterceptionDate DESC*/
  464.  
  465.  
  466.      CREATE TABLE work.JORA_MIG_PrimaryOperation AS
  467.         SELECT t4.Name as OperationName,
  468.               put(t4.operationalScopeid,DICTIONARY.) as OperationalScope,  
  469.               "Primary" as OperationReporting,
  470.               put(t4.operationsectortypeid,DICTIONARY.) as SectorType,     
  471. /*            put(t1.OperationalAreaId,JORA_OP_AREA.) as OperationalArea,*/
  472.               put(t1.OperationalAreaId,JORA_LOC_PARENT.) as ParentLocation,
  473. /*            put(t1.OperationalAreaId,JORA_LOC_BS.) as Bordersection,*/
  474. /*            put(t1.OperationalAreaId,JORA_LOC_MS.) as MemberState,*/
  475. /*            put(t1.OperationalAreaId,JORA_LOC_KBS.) as KeyBorderSection,*/
  476.               t1.DetectedBy,    
  477.               t1.InterceptionDate,
  478.               put(datepart(t1.InterceptionDate),YYMMDD10.) as InterceptionDate_day,
  479.               put(timepart(t1.InterceptionDate),time8.) as InterceptionDate_time,
  480.               put(datepart(t1.InterceptionDate),YYMM.) as Interceptiondate_YYYYMM,
  481.               t1.detectiontime,
  482.               put(datepart(t1.detectiontime),YYMMDD10.) as detectiontime_day,
  483.               put(timepart(t1.detectiontime),time8.) as detectiontime_time,
  484.               put(datepart(t1.detectiontime),YYMM.) as detectiontime_YYYYMM,
  485.               t1.InterceptionPlaceComments,
  486.               t1.InterceptedBy,    
  487.               t1.CreateDate,
  488.               t1.statusid, /*Status of the incident*/
  489.               put(t1.approverID,Sys_user.) as ApproverID,  
  490.               put(datepart(t1.CreateDate),YYMMDD10.) as CreateDate_day,
  491.               put(timepart(t1.CreateDate),time8.) as CreateDate_time,
  492.               put(datepart(t1.CreateDate),YYMM.) as Createdate_YYYYMM,
  493.               put(year(datepart(t1.CreateDate)),4.)||"Wk"||put(week(datepart(t1.CreateDate),'v'),2.) as Createdate_YYYYWK,
  494.               t1.make,
  495.               t1.model,
  496.               put(t1.platenationalityid,Jora_nat.) as PlateNationality,
  497.               put(t1.drivernationalityid,Jora_nat.) as DriverNationality,
  498.               t1.Latitude,
  499.               t1.LatitudeDetection,        
  500.               t1.Longitude,
  501.               t1.LongitudeDetection,    
  502.               t1.TimeOfDeparture,
  503.               t1.Disembarkation,
  504.               t1.PlaceOfDeparture,
  505.               t1.Comments,
  506.               t1.DeathCases,
  507.               t1.IncidentNumber,
  508.               t1.MarketValue,
  509.               t1.MigrantsDeterred,
  510.               t1.TransportMeansNumber,
  511.               t1.SearchAndRescueInvolved,
  512.               t1.SmugglingOfNumber,
  513.               put(t1.countryofdepartureID,Jora_nat.) as CountryOfDeparture,
  514.               put(t1.countryofdepartureID,Jora_isocode.) as CountryOfDeparture_iso,
  515.               put(t1.countryofdestinationID,Jora_nat.) as CountryOfDestination,
  516.               put(t1.countryofdestinationID,Jora_isocode.) as CountryOfDestination_iso,
  517.               put(t1.ReferenceId,DICTIONARY.) as RefOperationalArea,
  518.                put(t1.IncidentTypeId,DICTIONARY.) as IncidentType,
  519.                put(t1.BoatDestroyedById,DICTIONARY.) as BoatDestroyedBy,
  520.                put(t1.SmugglingOfId,DICTIONARY.) as SmugglingOf,
  521.                put(t1.PlaceOfInterceptionId ,DICTIONARY.) as PlaceOfInterception,
  522. /*               put(t1.ZoneId ,DICTIONARY.) As Zone,*/
  523.                put(t1.DestinationMethodOfTransportId ,DICTIONARY.) as TransportType,
  524.               t2.firstname,
  525.               t2.lastname,
  526.               put(t2.outcomeid,DICTIONARY.) as outcome,
  527.               t2.nationalityID,          
  528.               t2.nationalityclaimedID,
  529.               t2.nationalitypresumedID,
  530.               put(t2.GenderId ,DICTIONARY.) as Gender,
  531.               t2.age,
  532.                put(t2.ImmigrationStatusId ,DICTIONARY.) as ImmigrationStatusId,
  533.                put(t2.PersonRoleId ,DICTIONARY.) as Mig_PersonRole,
  534.                put(t2.RefusalReasonId ,DICTIONARY.) as Mig_RefusalReason,
  535.                1 as frequency,
  536.               count(incidentnumber) as NbRecord,
  537.               t1.GuestOfficerInvolved as GuestOfficerInvolved
  538.            FROM JORARAU.Incident t1
  539.           INNER JOIN JORARAU.MigrantInformation t2 ON (t1.Id = t2.IncidentId)
  540.           INNER JOIN JORARAU.Operation t4 ON (t1.OperationId = t4.Id)
  541.          Where t1.isdeleted NE 1  and t1.isaccepted=1
  542.          group by OperationName, IncidentNumber
  543.         ORDER BY t1.InterceptionDate DESC;
  544.  
  545.  CREATE TABLE work.JORA_MIG_SecondaryOperation AS
  546.         SELECT t4.Name as OperationName,
  547.               put(t4.operationalScopeid,DICTIONARY.) as OperationalScope,  
  548.               "Secondary" as OperationReporting,
  549.               put(t4.operationsectortypeid,DICTIONARY.) as SectorType,
  550. /*            put(t1.OperationalAreaId,JORA_OP_AREA.) as OperationalArea,*/
  551.               put(t1.OperationalAreaId,JORA_LOC_PARENT.) as ParentLocation,
  552. /*            put(t1.OperationalAreaId,JORA_LOC_BS.) as Bordersection,*/
  553. /*            put(t1.OperationalAreaId,JORA_LOC_MS.) as MemberState,*/
  554. /*            put(t1.OperationalAreaId,JORA_LOC_KBS.) as KeyBorderSection,*/
  555.               t1.DetectedBy,    
  556.               t1.InterceptionDate,
  557.               put(datepart(t1.InterceptionDate),YYMMDD10.) as InterceptionDate_day,
  558.               put(timepart(t1.InterceptionDate),time8.) as InterceptionDate_time,
  559.               put(datepart(t1.InterceptionDate),YYMM.) as Interceptiondate_YYYYMM,
  560.               t1.detectiontime,
  561.               put(datepart(t1.detectiontime),YYMMDD10.) as detectiontime_day,
  562.               put(timepart(t1.detectiontime),time8.) as detectiontime_time,
  563.               put(datepart(t1.detectiontime),YYMM.) as detectiontime_YYYYMM,
  564.               t1.InterceptionPlaceComments,
  565.               t1.InterceptedBy,    
  566.               t1.CreateDate,
  567.               t1.statusid, /*Status of the incident*/
  568.               put(t1.approverID,Sys_user.) as ApproverID,  
  569.               put(datepart(t1.CreateDate),YYMMDD10.) as CreateDate_day,
  570.               put(timepart(t1.CreateDate),time8.) as CreateDate_time,
  571.               put(datepart(t1.CreateDate),YYMM.) as Createdate_YYYYMM,
  572.               put(year(datepart(t1.CreateDate)),4.)||"Wk"||put(week(datepart(t1.CreateDate),'v'),2.) as Createdate_YYYYWK,
  573.               t1.make,
  574.               t1.model,
  575.               put(t1.platenationalityid,Jora_nat.) as PlateNationality,
  576.               put(t1.drivernationalityid,Jora_nat.) as DriverNationality,
  577.               t1.Latitude,
  578.               t1.LatitudeDetection,        
  579.               t1.Longitude,
  580.               t1.LongitudeDetection,    
  581.               t1.TimeOfDeparture,
  582.               t1.Disembarkation,
  583.               t1.PlaceOfDeparture,
  584.               t1.Comments,
  585.               t1.DeathCases,
  586.               t1.IncidentNumber,
  587.               t1.MarketValue,
  588.               t1.MigrantsDeterred,
  589.               t1.TransportMeansNumber,
  590.               t1.SearchAndRescueInvolved,
  591.               t1.SmugglingOfNumber,
  592.               put(t1.countryofdepartureID,Jora_nat.) as CountryOfDeparture,
  593.               put(t1.countryofdepartureID,Jora_isocode.) as CountryOfDeparture_iso,
  594.               put(t1.countryofdestinationID,Jora_nat.) as CountryOfDestination,
  595.               put(t1.countryofdestinationID,Jora_isocode.) as CountryOfDestination_iso,
  596.               put(t1.ReferenceId,DICTIONARY.) as RefOperationalArea,
  597.               put(t1.IncidentTypeId,DICTIONARY.) as IncidentType,
  598.               put(t1.BoatDestroyedById,DICTIONARY.) as BoatDestroyedBy,
  599.               put(t1.SmugglingOfId,DICTIONARY.) as SmugglingOf,
  600.               put(t1.PlaceOfInterceptionId ,DICTIONARY.) as PlaceOfInterception,
  601. /*              put(t1.ZoneId ,DICTIONARY.) As Zone,*/
  602.               put(t1.DestinationMethodOfTransportId ,DICTIONARY.) as TransportType,
  603.               t2.firstname,
  604.               t2.lastname,
  605.               put(t2.outcomeid,DICTIONARY.) as outcome,
  606.               t2.nationalityID,
  607.               t2.nationalityclaimedID,
  608.               t2.nationalitypresumedID,
  609.               put(t2.GenderId ,DICTIONARY.) as Gender,
  610.               t2.age,
  611.               put(t2.ImmigrationStatusId ,DICTIONARY.) as ImmigrationStatusId,
  612.               put(t2.PersonRoleId ,DICTIONARY.) as Mig_PersonRole,
  613.               put(t2.RefusalReasonId ,DICTIONARY.) as Mig_RefusalReason,
  614.                1 as frequency,
  615.               count(incidentnumber) as NbRecord,
  616.               t1.GuestOfficerInvolved as GuestOfficerInvolved
  617.            FROM JORARAU.Incident t1
  618.           INNER JOIN JORARAU.MigrantInformation t2 ON (t1.Id = t2.incidentId)
  619.           INNER JOIN JORARAU.IncidentRelatedOperation t3 ON (t1.Id = t3.IncidentId)
  620.           INNER JOIN JORARAU.Operation t4 ON (t3.OperationId = t4.Id)
  621.          Where t1.isdeleted NE 1  and t1.isaccepted=1
  622.          group by OperationName, IncidentNumber
  623.         ORDER BY t1.InterceptionDate DESC;
  624.  
  625. quit;
  626.  /*data shredstg.JORA_NAT;
  627. set work.Jora_nat_PrimaryOperation work.Jora_nat_SecondaryOperation;
  628. run;*/
  629.  
  630. *LOCK SHREDSTG.JORA_MIG;
  631.  
  632. data work.Jora_Mig_temp;
  633. set work.Jora_Mig_PrimaryOperation work.Jora_Mig_SecondaryOperation;
  634. run;
  635.  
  636. /*
  637.      data shredstg.JORA_NAT;
  638.      length Status $30 Nat_final_iso $3 Nat_final $50 Nat_confirmed $50 Nat_presumed $50 Nat_claimed $50 route $50 LastDepartureCtry $50;
  639.      
  640.      set shredstg.JORA_NAT;
  641.      if statusid=1 then status='Pending';
  642.      if statusid=2 then status='For LCC Verification';
  643.      if statusid=3 then status='For ICC Verification';
  644.      if statusid=4 then status='For FSC Verification';
  645.      if statusid=5 then status='Accepted';
  646.      
  647.      NatClaimedAndConfirmed = strip(Nat_nationality_confirmed);
  648.      if(NatClaimedAndConfirmed eq '.') then NatClaimedAndConfirmed = strip(Nat_nationality_claimed);
  649.  
  650.      if sectortype in ("AIR","LAND") and Detectiontime=. then
  651.         do;
  652.  
  653.             IncidentDate=CreateDate;
  654.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  655.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  656.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  657.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'v'),2.);
  658.            
  659.         end;
  660.     else if sectortype in ("AIR","LAND") and Detectiontime <>. then
  661.         do;
  662.             IncidentDate=detectiontime;
  663.             IncidentDate_Day= put(datepart(detectiontime),YYMMDD10.);
  664.             IncidentDate_Time= put(datepart(detectiontime),time8.);
  665.             IncidentDate_YYYYMM= put(datepart(detectiontime),YYMM.);
  666.             IncidentDate_YYYYWK=put(year(datepart(detectiontime)),4.)||"Wk"||put(week(datepart(detectiontime),'v'),2.) ;
  667.         end;
  668.     else if sectortype = "SEA" and interceptiondate=. then
  669.         do;
  670.             IncidentDate=CreateDate;
  671.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  672.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  673.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  674.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'v'),2.);
  675.         end;
  676.     else if sectortype = "SEA" and interceptiondate NE . then
  677.         do;
  678.             IncidentDate=interceptiondate;
  679.             IncidentDate_Day= put(datepart(interceptiondate),YYMMDD10.);
  680.             IncidentDate_Time= put(datepart(interceptiondate),time8.);
  681.             IncidentDate_YYYYMM= put(datepart(interceptiondate),YYMM.);
  682.             IncidentDate_YYYYWK=put(year(datepart(interceptiondate)),4.)||"Wk"||put(week(datepart(interceptiondate),'v'),2.);
  683.         end;
  684.  
  685.  
  686.      SmugglingNbAdjusted=SmugglingOfNumber/nbrecord;
  687.      drop statusid;
  688.  
  689.  
  690. /*Adjusting weeks for 2012
  691. if datepart(createdate)="31dec2012"d then createdate_YYYYWK="2013Wk 1";
  692. if datepart(createdate)="01jan2012"d then createdate_YYYYWK="2011Wk52";
  693. if datepart(IncidentDate)="31dec2012"d then IncidentDate_YYYYWK="2013Wk 1";
  694. if datepart(IncidentDate)="01jan2012"d then IncidentDate_YYYYWK="2011Wk52";
  695.  
  696.  /*"Final" nationality calculation
  697.  
  698.     Nat_confirmed=put(nationalityConfirmedID,Jora_nat.);
  699.     Nat_claimed=put(nationalityclaimedID,Jora_nat.);
  700.     Nat_presumed=put(nationalitypresumedID,Jora_nat.);
  701.    
  702.  
  703.         if strip(nat_confirmed) Not in (".",""," ") then do;
  704.                                                 Nat_Final=Nat_confirmed;
  705.                                                 Nat_final_iso= put(nationalityconfirmedID,Jora_isocode.);
  706.                                                 end;
  707.         else if strip(Nat_presumed) Not in (".",""," ") then do;
  708.                                                             Nat_Final=Nat_presumed;
  709.                                                             Nat_final_iso= put(nationalitypresumedID,Jora_isocode.);
  710.                                                             end;
  711.  
  712.                 else if strip(Nat_claimed) Not in (".",""," ") then do;
  713.                                                             Nat_Final=Nat_claimed;
  714.                                                             Nat_final_iso= put(nationalityclaimedID,Jora_isocode.);
  715.                                                             end;
  716.             /*end nationnality computation
  717.  
  718. IF OperationName='EPN-INDALO 2012' and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'Other', 'Smuggling', 'Migrants deterred') and Mig_PersonRole in ('.', 'Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Western Mediterranean Route (ESP-land and sea)';
  719. IF OperationName='EPN HERA 2012' and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route=' Western African Route';
  720. IF OperationName in ('EPN-AENEAS 2011','EPN Aeneas 2012') and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Central Mediterranean Route (ITA-Apulia&Calabria)';
  721. IF OperationName in ('EPN-HERMES 2011','EPN HERMES 2012') and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Central Mediterranean Route (ITA and MLT, excludin';
  722. IF (OperationName in ('Poseidon Land 2013','Poseidon Land 2012','Poseidon Land 2011 Extension') and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'hiding in transportation means','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor')) Or (OperationName in ('Poseidon Sea 2013','Poseidon Sea 2012','Poseidon Sea 2011') and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'hiding in transportation means','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated','Other','Unaccompanied minor') and Zone in ('Op. Area A','Op. Area K')) then Route= 'Eastern Mediterranean route (GRC,BGR,CYP-land and';
  723. IF OperationName in ('Poseidon Sea 2013','Poseidon Sea 2012','Poseidon Sea 2011') and Status='Accepted' and IncidentType in ('Facilitation - smuggling of humans', 'Illegal border crossing', 'hiding in transportation means','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') and Zone='Op. Area B' then Route= 'Secondary movements to ITA';
  724. if Sectortype='LAND'  then LastDepartureCtry=Bordersection;
  725. if Sectortype='SEA'  then LastDepartureCtry=CountryofDeparture;
  726. if strip(LastDepartureCtry) in ('.','','') then LastDepartureCtry='Unknown';
  727. format IncidentDate datetime.;
  728. run;
  729. */
  730.  
  731.  data work.jora_mig_temp;
  732.     length OperationNameGroup $40Status $30 route $50 LastdepartureCtry $50 Nat_final_iso $3 Nat_final $50 Nat_confirmed $50 Nat_presumed $50 Nat_claimed $50 GuestOfficerInvolved1 $5;
  733.     set work.jora_mig_temp;
  734.  
  735. /*Statusid enumeration*/
  736.  
  737.     if statusid=1 then
  738.         status='Pending';
  739.     if statusid=2 then
  740.         status='For LCC Verification';
  741.     if statusid=3 then
  742.         status='For ICC Verification';
  743.     if statusid=4 then
  744.         status='For FSC Verification';
  745.     if statusid=5 then
  746.         status='Accepted';
  747.     drop statusid;
  748.  
  749.     if sectortype in ("AIR","LAND") and Detectiontime=. then
  750.         do;
  751.             IncidentDate=CreateDate;
  752.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  753.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  754.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  755.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'v'),2.) ;
  756.         end;
  757.     else if sectortype in ("AIR","LAND") and Detectiontime <>. then
  758.         do;
  759.             IncidentDate=detectiontime;
  760.             IncidentDate_Day= put(datepart(detectiontime),YYMMDD10.);
  761.             IncidentDate_Time= put(datepart(detectiontime),time8.);
  762.             IncidentDate_YYYYMM= put(datepart(detectiontime),YYMM.);
  763.             IncidentDate_YYYYWK=put(year(datepart(detectiontime)),4.)||"Wk"||put(week(datepart(detectiontime),'v'),2.) ;
  764.         end;
  765.     else if sectortype = "SEA" and interceptiondate=. then
  766.         do;
  767.             IncidentDate=CreateDate;
  768.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  769.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  770.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  771.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'v'),2.);
  772.         end;
  773.     else if sectortype = "SEA" and interceptiondate<>. then
  774.         do;
  775.             IncidentDate=interceptiondate;
  776.             IncidentDate_Day= put(datepart(interceptiondate),YYMMDD10.);
  777.             IncidentDate_Time= put(datepart(interceptiondate),time8.);
  778.             IncidentDate_YYYYMM= put(datepart(interceptiondate),YYMM.);
  779.             IncidentDate_YYYYWK=put(year(datepart(interceptiondate)),4.)||"Wk"||put(week(datepart(interceptiondate),'v'),2.) ;
  780.         end;
  781.          SmugglingNbAdjusted=SmugglingOfNumber/nbrecord;
  782.  
  783.  
  784.          /*"Final" nationality calculation*/
  785.     Nat_confirmed=put(nationalityID,Jora_nat.);
  786.     Nat_claimed=put(nationalityclaimedID,Jora_nat.);
  787.     Nat_presumed=put(nationalitypresumedID,Jora_nat.);
  788.  
  789.     if strip(nat_confirmed) Not in (".",""," ") then do;
  790.                                                 Nat_Final=Nat_confirmed;
  791.                                                 Nat_final_iso= put(nationalityID,Jora_isocode.);
  792.                                                 end;
  793.         else if strip(Nat_presumed) Not in (".",""," ") then do;
  794.                                                             Nat_Final=Nat_presumed;
  795.                                                             Nat_Final_iso= put(nationalitypresumedID,Jora_isocode.);
  796.                                                             end;
  797.  
  798.                 else if strip(Nat_claimed) Not in (".",""," ") then do;
  799.                                                             Nat_Final=Nat_claimed;
  800.                                                             Nat_Final_iso=put(nationalityclaimedID,Jora_isocode.);
  801.                                                             end;
  802.             /*end nationnality computation*/
  803.  
  804.  
  805.     /*Adjusting weeks for 2012*/
  806. if datepart(createdate)="31dec2012"d then createdate_YYYYWK="2013Wk 1";
  807. if datepart(createdate)="01jan2012"d then createdate_YYYYWK="2011Wk52";
  808.  
  809. if datepart(IncidentDate)="31dec2012"d then IncidentDate_YYYYWK="2013Wk 1";
  810. if datepart(IncidentDate)="01jan2012"d then IncidentDate_YYYYWK="2011Wk52";
  811.  
  812. /*Adjusting weeks for 2013*/
  813. if datepart(createdate)="30dec2013"d then createdate_YYYYWK="2014Wk 1";
  814. if datepart(createdate)="31dec2013"d then createdate_YYYYWK="2014Wk 1";
  815.  
  816. if datepart(IncidentDate)="30dec2013"d then IncidentDate_YYYYWK="2014Wk 1";
  817. if datepart(IncidentDate)="31dec2013"d then IncidentDate_YYYYWK="2014Wk 1";
  818.  
  819.  
  820. /*Routes filters(to be udpated)*/
  821. IF OperationName in ('EPN-INDALO 2012','EPN-INDALO 2013') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Other', 'Smuggling of goods', 'Migrants deterred') and Mig_PersonRole in ('.', 'Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Western Mediterranean Route (ESP-land and sea)';
  822. IF OperationName in('EPN HERA 2012','EPN HERA 2013') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route=' Western African Route';
  823. IF OperationName in ('EPN-AENEAS 2011','EPN Aeneas 2012','EPN Aeneas 2013') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Central Mediterranean Route (ITA-Apulia&Calabria)';
  824. IF OperationName in ('EPN-HERMES 2011','EPN HERMES 2012','EPN HERMES 2013') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') then Route='Central Mediterranean Route (ITA and MLT, excludin';
  825. IF (OperationName in ('Poseidon Land 2013','Poseidon Land 2012','Poseidon Land 2011 Extension') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Hiding in transportation means / clandestine','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor')) Or (OperationName in ('Poseidon Sea 2013','Poseidon Sea 2012','Poseidon Sea 2011') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Hiding in transportation means / clandestine','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated','Other','Unaccompanied minor') and Zone in ('Op. Area A','Op. Area K')) then Route= 'Eastern Mediterranean route (GRC,BGR,CYP-land and';
  826. IF OperationName in ('Poseidon Sea 2013','Poseidon Sea 2012','Poseidon Sea 2011') and Status='Accepted' and IncidentType in ('Facilitation (smuggling of humans)', 'Illegal border crossing', 'Hiding in transportation means / clandestine','Other') and Mig_PersonRole in ('Irregular migrant', 'Irregular migrant facilitated', 'Other', 'Unaccompanied minor') and Zone='Op. Area B' then Route= 'Secondary movements to ITA';
  827. if Sectortype='LAND'  then LastDepartureCtry=Bordersection;
  828. if Sectortype='SEA'  then LastDepartureCtry=CountryofDeparture;
  829. if strip(LastDepartureCtry) in ('.','','') then LastDepartureCtry='Unknown';
  830. format IncidentDate datetime.;
  831.  
  832. /*Group operation for year to year comparison*/
  833.     operationnamegroup=operationname;
  834.     if upcase(operationname) in ('EPN AENEAS 2012','EPN AENEAS 2013','EPN-AENEAS 2011') then operationNameGroup="Aeneas";
  835.     if upcase(operationname) in ('EPN HERMES 2012','EPN HERMES 2013','EPN-HERMES 2011') then operationNameGroup="Hermes";
  836.     if upcase(operationname) in ('EPN-INDALO 2012','EPN-INDALO 2013') then operationNameGroup="Indalo";
  837.     if upcase(operationname) in ('FOCAL POINTS 2011 LAND  EXTENSION','FOCAL POINTS 2012 LAND','FOCAL POINTS 2013 LAND') then operationNameGroup="Focal Points Land";
  838.     if upcase(operationname) in ('FOCAL POINTS SEA 2012','FOCAL POINTS SEA 2013') then operationNameGroup="Focal Points Sea";
  839.     if upcase(operationname) in ('POSEIDON LAND 2011 EXTENSION','POSEIDON LAND 2012','POSEIDON LAND 2013') then operationNameGroup="Poseidon Land";
  840.     if upcase(operationname) in ('POSEIDON SEA 2011','POSEIDON SEA 2011 REPORTING POINTS','POSEIDON SEA 2012','POSEIDON SEA 2013') then operationNameGroup="Poseidon Sea";
  841.  
  842. if GuestOfficerInvolved=0 then GuestOfficerInvolved1="No";
  843. if GuestOfficerInvolved=1 then GuestOfficerInvolved1="Yes";
  844. Drop GuestOfficerInvolved;
  845.  
  846. run;
  847.  
  848. /*export data to sql*/
  849. *proc sql;
  850. *drop table frandata.JORA_MIG;/*, frandata.JORA_NAT;*/
  851. *quit;
  852.  
  853. /*data frandata.JORA_Mig;
  854. set shredstg.JORA_mig;
  855. run;*/
  856.  
  857. /*
  858. data frandata.JORA_nat;
  859. set shredstg.JORA_NAT;
  860. run;*/
  861.  
  862. /*Dictionary updates in the last 30 days*/
  863. proc sql;
  864. create table dic_Update as
  865. select *
  866. from JORARAU.DICTIONARY
  867. where datepart(updatedate)>="&SYSDATE9."d-30;
  868.  
  869. drop table /*location*/ JORA_NAT_PrimaryOperation, JORA_NAT_SecondaryOperation, JORA_MIG_PrimaryOperation, JORA_MIG_SecondaryOperation;
  870. quit;
  871.  
  872.  
  873. /*Document tables*/
  874. proc sql;
  875. CREATE TABLE work.JORA_PersonDoc AS
  876.         SELECT t4.Name as OperationName,
  877.               put(t4.operationalScopeid,DICTIONARY.) as OperationalScope,  
  878.               put(t4.operationsectortypeid,DICTIONARY.) as SectorType,
  879.               /*Incident variables*/
  880. /*            put(t1.OperationalAreaId,JORA_OP_AREA.) as OperationalArea,*/
  881.               put(t1.OperationalAreaId,JORA_LOC_PARENT.) as ParentLocation,
  882. /*            put(t1.OperationalAreaId,JORA_LOC_BS.) as Bordersection,*/
  883. /*            put(t1.OperationalAreaId,JORA_LOC_MS.) as MemberState,*/
  884. /*            put(t1.OperationalAreaId,JORA_LOC_KBS.) as KeyBorderSection,*/
  885.               t1.DetectedBy,    
  886.               t1.InterceptionDate,
  887.               t1.modusoperandi,
  888.               put(datepart(t1.InterceptionDate),YYMMDD10.) as InterceptionDate_day,
  889.               put(timepart(t1.InterceptionDate),time8.) as InterceptionDate_time,
  890.               put(datepart(t1.InterceptionDate),YYMM.) as Interceptiondate_YYYYMM,
  891.               t1.detectiontime,
  892.               put(datepart(t1.detectiontime),YYMMDD10.) as detectiontime_day,
  893.               put(timepart(t1.detectiontime),time8.) as detectiontime_time,
  894.               put(datepart(t1.detectiontime),YYMM.) as detectiontime_YYYYMM,
  895.               t1.InterceptionPlaceComments,
  896.               t1.InterceptedBy,    
  897.               t1.CreateDate,
  898.               t1.statusid, /*Status of the incident*/
  899.               put(t1.approverID,Sys_user.) as ApproverID,  
  900.               put(datepart(t1.CreateDate),YYMMDD10.) as CreateDate_day,
  901.               put(timepart(t1.CreateDate),time8.) as CreateDate_time,
  902.               put(datepart(t1.CreateDate),YYMM.) as Createdate_YYYYMM,
  903.               put(year(datepart(t1.CreateDate)),4.)||"Wk"||put(week(datepart(t1.CreateDate),'w'),2.) as Createdate_YYYYWK,
  904.               t1.make,
  905.               t1.model,
  906.               put(t1.platenationalityid,Jora_nat.) as PlateNationality,
  907.               put(t1.drivernationalityid,Jora_nat.) as DriverNationality,
  908.               t1.Latitude,
  909.               t1.LatitudeDetection,        
  910.               t1.Longitude,
  911.               t1.LongitudeDetection,    
  912.               t1.TimeOfDeparture,
  913.               t1.Disembarkation,
  914.               t1.PlaceOfDeparture,
  915.               t1.Comments as IncidentComments,
  916.               t1.DeathCases,
  917.               t1.IncidentNumber,
  918.               t1.MarketValue,
  919.               t1.MigrantsDeterred,
  920.               t1.TransportMeansNumber,
  921.               t1.SearchAndRescueInvolved,
  922.               t1.SmugglingOfNumber,
  923.               put(t1.countryofdepartureID,Jora_nat.) as CountryOfDeparture,
  924.               put(t1.countryofdepartureID,Jora_isocode.) as CountryOfDeparture_iso,
  925.               put(t1.countryofdestinationID,Jora_nat.) as CountryOfDestination,
  926.               put(t1.countryofdestinationID,Jora_isocode.) as CountryOfDestination_iso,
  927.               put(t1.ReferenceId,DICTIONARY.) as RefOperationalArea,
  928.               put(t1.IncidentTypeId,DICTIONARY.) as IncidentType,
  929.               put(t1.BoatDestroyedById,DICTIONARY.) as BoatDestroyedBy,
  930.               put(t1.SmugglingOfId,DICTIONARY.) as SmugglingOf,
  931.               put(t1.PlaceOfInterceptionId ,DICTIONARY.) as PlaceOfInterception,
  932. /*              put(t1.ZoneId ,DICTIONARY.) As Zone,*/
  933.               put(t1.DestinationMethodOfTransportId ,DICTIONARY.) as TransportType,
  934.               /*MigrantInformation Variables*/
  935.               put(t2.outcomeid,DICTIONARY.) as outcome,
  936.               t2.nationalityID,
  937.               t2.nationalityclaimedID,
  938.               t2.nationalitypresumedID,
  939.               put(t2.GenderId ,DICTIONARY.) as Gender,
  940.               t2.age,
  941.               put(t2.ImmigrationStatusId ,DICTIONARY.) as ImmigrationStatusId,
  942.               put(t2.PersonRoleId ,DICTIONARY.) as Mig_PersonRole,
  943.               put(t2.RefusalReasonId ,DICTIONARY.) as Mig_RefusalReason,
  944.               /*PersonDocument Variables*/
  945.               t3.comments as PersonDocComments,
  946.               t3.ExpiringON,
  947.               t3.IssuingDate,
  948.               t3.number as DocNumber,
  949.               t3.typeofdocumentid as TypeOfDocument,
  950.               t3.whereIssued,
  951.               put(t3.Issuingcountryid,Jora_nat.) as IssuingCountry,
  952.               put(t3.TravelDocumentTypeid,DICTIONARY.) as TravelDocumentType,
  953.               put(t3.ExibitedConcealedid,DICTIONARY.) as ExibitedConcealed,
  954.               put(t3.ForgeryTypeId,DICTIONARY.) as ForgeryType,
  955.               put(t3.FoundAtId,DICTIONARY.) as FoundAt,
  956.               put(t3.StatusId,DICTIONARY.) as StatusOfDocId,
  957.               t3.MigrantId,
  958.               put(t3.SupportiveDocumentTypeId,DICTIONARY.) as SupportiveDocumentType,
  959.               put(t3.VisaDocumentTypeId,DICTIONARY.) as VisaDocumentType,
  960.               /*DocumentAlert
  961.               t5.Description as DocAlertDescription,
  962.               t5.RoutingDescription,
  963.               put(t5.GenderId,DICTIONARY.) as DocAlertGender,
  964.               put(t5.NationalityofHolderId,Jora_nat.) as NationalityofHolder,
  965.               put(t5.TravelDestinationId,Jora_nat.) as TravelDestination,
  966.               put(t5.TravelFromId,Jora_nat.) as TravelFrom,
  967.               put(t5.TravelViaId,Jora_nat.) as Travelvia,*/
  968.               1 as NbDoc
  969.           FROM Jorarau.persondocument t3
  970.           left JOIN Jorarau.MigrantInformation t2 ON (t2.Id = t3.MigrantId)
  971.           left join Jorarau.Incident t1 ON (t1.id=t2.IncidentId)
  972.           left JOIN Jorarau.Operation t4 ON (t4.Id=t1.OperationId)
  973.           /*left JOIN Jorarau.documentAlert t5 ON (t5.Id=t3.DocumentAlertId)*/
  974.         Where t1.isdeleted <> 1 and put(t4.operationsectortypeid,DICTIONARY.) in ('LAND','SEA')
  975.         ORDER BY t1.InterceptionDate DESC;
  976.  
  977. quit;
  978. data work.Jora_PersonDoc;
  979.      length Status $30 TypeofDoc $30;
  980.      set work.jora_Persondoc;
  981.      if statusid=1 then status='Pending';
  982.      if statusid=2 then status='For LCC Verification';
  983.      if statusid=3 then status='For ICC Verification';
  984.      if statusid=4 then status='For FSC Verification';
  985.      if statusid=5 then status='Accepted';
  986.  
  987.      if typeofdocument=1 then TypeofDoc="Travel";
  988.      if typeofdocument=2 then TypeofDoc="Supportive";
  989.      if typeofdocument=3 then TypeofDoc="Visa";          
  990.    
  991.  
  992.      if sectortype = "LAND" and Detectiontime=. then
  993.         do;
  994.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  995.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  996.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  997.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'w'),2.) ;
  998.         end;
  999.     else if sectortype = "LAND" and Detectiontime <>. then
  1000.         do;
  1001.             IncidentDate_Day= put(datepart(detectiontime),YYMMDD10.);
  1002.             IncidentDate_Time= put(datepart(detectiontime),time8.);
  1003.             IncidentDate_YYYYMM= put(datepart(detectiontime),YYMM.);
  1004.             IncidentDate_YYYYWK=put(year(datepart(detectiontime)),4.)||"Wk"||put(week(datepart(detectiontime),'w'),2.) ;
  1005.         end;
  1006.     else if sectortype = "SEA" and interceptiondate=. then
  1007.         do;
  1008.             IncidentDate_Day= put(datepart(CreateDate),YYMMDD10.);
  1009.             IncidentDate_Time= put(datepart(CreateDate),time8.);
  1010.             IncidentDate_YYYYMM= put(datepart(CreateDate),YYMM.);
  1011.             IncidentDate_YYYYWK=put(year(datepart(CreateDate)),4.)||"Wk"||put(week(datepart(CreateDate),'w'),2.);
  1012.         end;
  1013.     else if sectortype = "SEA" and interceptiondate<>. then
  1014.         do;
  1015.             IncidentDate_Day= put(datepart(interceptiondate),YYMMDD10.);
  1016.             IncidentDate_Time= put(datepart(interceptiondate),time8.);
  1017.             IncidentDate_YYYYMM= put(datepart(interceptiondate),YYMM.);
  1018.             IncidentDate_YYYYWK=put(year(datepart(interceptiondate)),4.)||"Wk"||put(week(datepart(interceptiondate),'w'),2.) ;
  1019.         end;
  1020.          /*"Final" nationality calculation*/
  1021.     Nat_confirmed=put(nationalityID,Jora_nat.);
  1022.     Nat_claimed=put(nationalityclaimedID,Jora_nat.);
  1023.     Nat_presumed=put(nationalitypresumedID,Jora_nat.);
  1024.  
  1025.     if strip(nat_confirmed) Not in (".",""," ") then do;
  1026.                                                 Nat_Final=Nat_confirmed;
  1027.                                                 Nat_final_iso= put(nationalityID,Jora_isocode.);
  1028.                                                 end;
  1029.         else if strip(Nat_presumed) Not in (".",""," ") then do;
  1030.                                                             Nat_Final=Nat_presumed;
  1031.                                                             Nat_Final_iso= put(nationalitypresumedID,Jora_isocode.);
  1032.                                                             end;
  1033.  
  1034.                 else if strip(Nat_claimed) Not in (".",""," ") then do;
  1035.                                                             Nat_Final=Nat_claimed;
  1036.                                                             Nat_Final_iso=put(nationalityclaimedID,Jora_isocode.);
  1037.                                                             end;
  1038.             /*end nationnality computation*/
  1039.  
  1040. /*Adjusting weeks for 2012*/
  1041. if datepart(createdate)="31dec2012"d then createdate_YYYYWK="2013Wk 1";
  1042. if datepart(createdate)="01jan2012"d then createdate_YYYYWK="2011Wk52";
  1043.  
  1044. if datepart(IncidentDate)="31dec2012"d then IncidentDate_YYYYWK="2013Wk 1";
  1045. if datepart(IncidentDate)="01jan2012"d then IncidentDate_YYYYWK="2011Wk52";
  1046.  
  1047. /*Adjusting weeks for 2013*/
  1048. if datepart(createdate)="30dec2013"d then createdate_YYYYWK="2014Wk 1";
  1049. if datepart(createdate)="31dec2013"d then createdate_YYYYWK="2014Wk 1";
  1050.  
  1051. if datepart(IncidentDate)="30dec2013"d then IncidentDate_YYYYWK="2014Wk 1";
  1052. if datepart(IncidentDate)="31dec2013"d then IncidentDate_YYYYWK="2014Wk 1";
  1053.  
  1054.      
  1055. drop TypeofDocument;
  1056. drop statusid;
  1057. run;
  1058.  
  1059. proc sql;
  1060.     create table tmp_BS as
  1061.     select t2.id as IncidentId, IncidentNumber,
  1062.     case when missing(t4.CountryId) NE 0 then "" else strip(put(t4.CountryId,fmt_country_long.)) end as MemberState,
  1063.     case when missing(t4.BorderSectionId) NE 0 then "" else strip(put(t4.BorderSectionId,fmt_country_long.)) end as BorderSection,
  1064.     /* BorderSection */
  1065.     (case when missing(t4.CountryId) NE 0 then "" else put(t4.CountryId,   fmt_country_short.) end || case when missing(t4.CountryId) NE 0 or missing(t4.BorderSectionId) NE 0 then ""
  1066.     else " - " end || case when missing(t4.BorderSectionId) NE 0 then "" else put(t4.BorderSectionId,   fmt_country_short.) end) LABEL="Key border section" AS KeyBorderSection,
  1067.  
  1068.     /* OperationalArea */   %FormatValue(t2.ZoneId, fmt_joraDict) LABEL="Operational area" AS OperationalArea,
  1069.     /* ReportingUnit */     %FormatValue(t3.ReportingLocationId, fmt_joraDict) LABEL="Reporting unit" AS ReportingUnit
  1070.     FROM JORARAU.Operation t1
  1071.         RIGHT JOIN JORARAU.Incident t2 ON (t1.Id = t2.OperationId)
  1072.         LEFT JOIN JORARAU.Location t3 ON (t2.OperationalAreaId = t3.Id)
  1073.         INNER JOIN JORARAU.Dictionary t4 ON (t3.ReportingLocationId = t4.Id)
  1074.     ;
  1075. quit;
  1076.  
  1077. proc sql;
  1078.     create table shredstg.jora_mig2 as
  1079.     select * from work.jora_mig_temp/*(drop=Memberstate Bordersection Keybordersection)*/ as t1
  1080.     left outer join tmp_BS as t2
  1081.     on (t1.IncidentNumber=t2.IncidentNumber);
  1082.  
  1083.     create table shredstg.Jora_PersonDoc2 as
  1084.     select * from work.Jora_PersonDoc/*(drop=Memberstate Bordersection Keybordersection)*/ as t1
  1085.     left outer join tmp_BS as t2
  1086.     on (t1.IncidentNumber=t2.IncidentNumber);
  1087. quit;
  1088.  
  1089. *LOCK SHREDSTG.JORA_MIG clear;
  1090.  
  1091. proc datasets lib=work nolist nowarn;
  1092.     delete tmp_: test_: fmt_: dic_: jora_: location;
  1093. quit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement