sasjs-core
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese@sasjs/core — SAS Macro Library
@sasjs/core — SAS宏库
@sasjs/core is an MIT-licensed library of production-quality SAS macros for SAS application development, portable across SAS 9 (meta), Viya, and SASjs server.
@sasjs/core是一个基于MIT许可证的生产级SAS宏库,用于SAS应用开发,可在SAS 9(元数据)、Viya和SASjs server平台间移植。
Coding standards (mandatory)
编码标准(强制性)
- One macro per file; filename must match the macro name (lowercase, no spaces)
- Macro definitions must use parentheses: not
%macro x();%macro x; - Macro calls are NOT terminated with a semicolon: not
%my_macro()%my_macro(); - All macro variables must be declared to prevent scope leakage
%local - 2-space indentation, no tabs, no trailing spaces, no invisible characters, max line length 300 (hard lint limit) but keep lines to 80 chars max where possible
- Every file must have a Doxygen header:
sas
/**
@file
@brief One-line description of the macro
<h4> SAS Macros </h4>
@li mf_othermacro.sas
@param [in] paramname Description
@param [out] outparam Description
<h4> Related Macros </h4>
@li mp_related.sas
@version 9.4
@author Your Name
**/- 每个文件对应一个宏;文件名必须与宏名一致(小写,无空格)
- 宏定义必须使用括号:而非
%macro x();%macro x; - 宏调用不能以分号结尾:而非
%my_macro()%my_macro(); - 所有宏变量必须声明为,以防止作用域泄漏
%local - 使用2空格缩进,禁止使用制表符,禁止行尾空格和不可见字符,最大行长度为300(代码检查硬限制),但尽可能将行长度控制在80字符以内
- 每个文件必须包含Doxygen头注释:
sas
/**
@file
@brief One-line description of the macro
<h4> SAS Macros </h4>
@li mf_othermacro.sas
@param [in] paramname Description
@param [out] outparam Description
<h4> Related Macros </h4>
@li mp_related.sas
@version 9.4
@author Your Name
**/Folder / prefix conventions
文件夹/前缀约定
| Folder | Prefix | Platform |
|---|---|---|
| | All platforms |
| | SAS 9 metadata |
| | SAS 9 metadata (OS command dependent) |
| | Viya |
| | SASjs server |
| | Runtime platform detection |
| — | PROC FCMP functions, LUA wrappers, DDL |
Use macros when the macro returns a value usable in an expression; use for procedural macros that generate code/statements.
mf_mp_| 文件夹 | 前缀 | 平台 |
|---|---|---|
| | 所有平台 |
| | SAS 9元数据 |
| | SAS 9元数据(依赖操作系统命令) |
| | Viya |
| | SASjs server |
| | 运行时平台检测 |
| — | PROC FCMP函数、LUA包装器、DDL |
当宏返回可用于表达式的值时,使用前缀宏;当宏用于生成代码/语句的过程式操作时,使用前缀宏。
mf_mp_Reuse before writing
优先复用现有宏
Before writing a new macro, check the library for an existing one — common utilities already exist, e.g. (the deprecated is retained for backwards compatibility — don't use it in new code), , , , , (SAS datasets → JSON for ), , . Platform-specific variants exist under , , and are selected at compile time by the CLI.
mp_abortmf_abortmf_existdsmf_existvarmf_existfilerefmf_getusermp_jsonout_weboutmp_ds2ddlmp_hashdatasetmeta/viya/server/在编写新宏之前,请先检查库中是否已有现成的宏——常见工具类宏已存在,例如(已弃用的为兼容旧版本保留,请勿在新代码中使用)、、、、、(将SAS数据集转换为JSON输出到)、、。特定平台的变体宏位于、、目录下,由CLI在编译时自动选择。
mp_abortmf_abortmf_existdsmf_existvarmf_existfilerefmf_getusermp_jsonout_weboutmp_ds2ddlmp_hashdatasetmeta/viya/server/Aborting safely
安全终止程序
Never invoke from inside an block — as a procedural macro, the macro processor can continue executing statements after it before the abort takes effect. Use the condition parameter instead:
%mp_abort%if/%elseiftrue=sas
%mp_abort(iftrue= (&syscc ne 0)
,mac=&_program
,msg=%str(Something went wrong)
)When is called from within a block, SAS cannot exit cleanly (e.g. to ). Call after the include (OUTSIDE any macro wrapper) — it checks for an abort status:
%mp_abort%include_webout%mp_abort(mode=INCLUDE)work.mp_abort_errdssas
%mp_abort(mode=INCLUDE)Note: s inside macros should be performed with so the indicator is set and the abort dataset () is passed back to the calling program.
%include%mp_include()_SYSINCLUDEFILEDEVICEwork.mp_abort_errds切勿在块内调用——作为过程式宏,宏处理器可能在终止生效前继续执行后续语句。请改用条件参数:
%if/%else%mp_abortiftrue=sas
%mp_abort(iftrue= (&syscc ne 0)
,mac=&_program
,msg=%str(Something went wrong)
)当在块内调用时,SAS无法干净退出(例如输出到)。请在之后(宏包装器外部)调用——它会检查中的终止状态:
%include%mp_abort_webout%include%mp_abort(mode=INCLUDE)work.mp_abort_errdssas
%mp_abort(mode=INCLUDE)注意:宏内部的操作应使用,这样会设置标识,并将终止数据集()传递回调用程序。
%include%mp_include()_SYSINCLUDEFILEDEVICEwork.mp_abort_errdsLint and build
代码检查与构建
- Run after every change; do not consider work done until it passes
sasjs lint - NEVER bump the version in (semantic-release handles it)
package.json - Do NOT edit generated files by hand: ,
all.sas, themc_*.saswrappers, andlua/outputs are produced by the CI buildsasjsbuild/ - Markdown files: never hard-wrap; one paragraph per line
- 每次修改后运行;未通过检查则视为工作未完成
sasjs lint - 禁止手动修改中的版本号(由semantic-release自动处理)
package.json - 禁止手动编辑生成文件:、
all.sas、mc_*.sas目录下的包装器以及lua/目录下的输出文件均由CI构建生成sasjsbuild/ - Markdown文件:禁止手动换行;每段内容单独占一行