Type : SASHELP
Ce script ne traite pas directement de données. Il s'appuie sur des fonctions SAS internes pour la date/heure et la gestion de fichiers (comme 'date()', 'year()', 'put()', 'fileexist()', 'symexist()'). Il utilise également des macros externes ('%canonicalname', '%getpath') qui peuvent être considérées comme des dépendances, mais pas comme des sources de données externes non gérées.
| 1 | %macro newmacro(name, srcid=); |
| 2 | %IF "&srcid."="" %THEN |
| 3 | %DO; |
| 4 | |
| 5 | %IF not %symexist(g_curr) %THEN |
| 6 | %DO; |
| 7 | %put ERROR: SOURCE Folder not specified!; |
| 8 | %return; |
| 9 | %END; |
| 10 | %ELSE |
| 11 | %DO; |
| 12 | %let srcid=&g_curr; |
| 13 | %END; |
| 14 | %END; |
| 15 | %local fname; |
| 16 | %let fname=%canonicalname(&name.); |
| 17 | |
| 18 | %IF "&fname."="" %THEN |
| 19 | %DO; |
| 20 | %put ERROR: Specified macro name <&name.> is invalid!; |
| 21 | %return; |
| 22 | %END; |
| 23 | %local path; |
| 24 | %let path=%getpath(&fname., srcid=&srcid.); |
| 25 | |
| 26 | %IF "&path"="" %THEN |
| 27 | %DO; |
| 28 | %put ERROR: SOURCE Folder not specified!; |
| 29 | %goto testfile; |
| 30 | %END; |
| 31 | %ELSE %IF %sysfunc(fileexist(&path.)) %THEN |
| 32 | %DO; |
| 33 | %put NOTE: Macro<&fname.> has already existed!; |
| 34 | %goto testfile; |
| 35 | %END; |
| 36 | |
| 37 | %local author; |
| 38 | %let author=Daniel YU; |
| 39 | |
| 40 | DATA _null_; |
| 41 | file "&path."; |
| 42 | year=put(year(date()), 4.); |
| 43 | date=put(date(), yymmdd10.); |
| 44 | time=put(time(), tod8.); |
| 45 | put '/*************************************************'; |
| 46 | put '* Copyright(c) ' year 'coco, All Rights Reserved.'; |
| 47 | put "* @html/SAS Help Center_ isAuthorized Action.html &author."; |
| 48 | put '* @since ' date time; |
| 49 | put '* @code_sas_json_prod_multi/dsc_cdm_version_update_de.json 1.0'; |
| 50 | put "* "; |
| 51 | put '*************************************************/'; |
| 52 | put ' '; |
| 53 | put '%macro ' "&fname.();"; |
| 54 | put ' %* Please write code here;;'; |
| 55 | put '%mend;'; |
| 56 | stop; |
| 57 | RUN; |
| 58 | |
| 59 | %testfile: |
| 60 | %let path=%getpath(&fname., suffix=_test, srcid=&srcid.); |
| 61 | |
| 62 | %IF "&path"="" %THEN |
| 63 | %DO; |
| 64 | %put ERROR: SOURCE Folder not specified!; |
| 65 | %return; |
| 66 | %END; |
| 67 | %ELSE %IF %sysfunc(fileexist(&path.)) %THEN |
| 68 | %DO; |
| 69 | %put NOTE: Macro<&fname.> test has already existed!; |
| 70 | %return; |
| 71 | %END; |
| 72 | |
| 73 | DATA _null_; |
| 74 | file "&path."; |
| 75 | put "%*Please write test code here;;"; |
| 76 | put '%*%asserteq( ,%' "&fname.());"; |
| 77 | put '%*%assertne( ,%' "&fname.());"; |
| 78 | put '%*%assertref( );'; |
| 79 | RUN; |
| 80 | |
| 81 | %mend; |