Type : MIXTE
Le script utilise et modifie des tables SAS existantes dans les librairies `dsccnfg` et `dscwh`. Il crée également une table temporaire `cdm_version_hist` pour l'insertion dans la table d'historique principale.
| 1 | %macro dsc_cdm_version_update(version_num=); |
| 2 | %let ver_hist_ds=dsccnfg.cdm_version_hist; |
| 3 | /* if migrating from old version to schema16 then update the modified tables as per schema16 changes;*/ |
| 4 | %IF &version_num. = 16 %THEN |
| 5 | %DO; |
| 6 |
| 1 | %IF %sysfunc(exist(&ver_hist_ds.)) %THEN |
| 2 | %DO; |
| 3 | /* what is the old version num ;*/ |
| 4 | PROC SQL noprint; |
| 5 | select max(ver_num) into :cdm_ver_num from &ver_hist_ds. ; |
| 6 | QUIT; |
| 7 | |
| 8 | /* if current version is less than 16 that means we need to alter the existing tables ;*/ |
| 9 | %IF &cdm_ver_num. < 16 %THEN |
| 10 | %DO; |
| 11 |
| 1 | /* modify following datasets to change owner_nm & created_user_nm length to 256 char;*/ |
| 2 | %let dataset_list = CDM_CONTENT_DETAIL CDM_TASK_DETAIL; |
| 3 | %local i dataset; |
| 4 | %DO i = 1 %to %sysfunc(countw(&dataset_list)); /* Loop through the dataset list */ |
| 5 | %let dataset = %scan(&dataset_list, &i); /* Get the current dataset name */ |
| 6 | %let table_nm = dscwh.&dataset; /* Set the table name */ |
| 7 | %put updating &table_nm.; |
| 8 | %IF %sysfunc(exist(&table_nm.)) %THEN |
| 9 | %DO; /* Check if dataset exists */ |
| 10 | DATA &table_nm._bkp; /* Create backup dataset */ |
| 11 | SET &table_nm.; |
| 12 | RUN; |
| 13 | DATA &table_nm.; /* Modify original dataset */ |
| 14 | attrib owner_nm FORMAT=$256. |
| 15 | created_user_nm FORMAT=$256.; |
| 16 | SET &table_nm.; |
| 17 | RUN; |
| 18 | %END; |
| 19 | %ELSE |
| 20 | %DO; |
| 21 | %put &table_nm. not found ; |
| 22 | %END; |
| 23 | %END; |
| 24 |
| 1 | DATA cdm_version_hist; |
| 2 | attrib ver_num LENGTH= 8. |
| 3 | ver_create_dttm LENGTH=8. FORMAT=datetime25.6; |
| 4 | ver_num =&version_num.; |
| 5 | ver_create_dttm =datetime(); |
| 6 | RUN; |
| 7 | |
| 8 | PROC APPEND base=dsccnfg.cdm_version_hist DATA=cdm_version_hist; |
| 9 | RUN; |
| 10 | %END; |
| 11 | %END; |
| 12 | %END; |
| 13 | %EXIT: |
| 14 | |
| 15 | %mend dsc_cdm_version_update; |
| 16 |