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:
    %macro x();
    not
    %macro x;
  • Macro calls are NOT terminated with a semicolon:
    %my_macro()
    not
    %my_macro();
  • All macro variables must be declared
    %local
    to prevent scope leakage
  • 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

文件夹/前缀约定

FolderPrefixPlatform
base/
mf_
(function-style),
mp_
(procedure-style)
All platforms
meta/
mm_
SAS 9 metadata
metax/
mmx_
SAS 9 metadata (OS command dependent)
viya/
mv_
Viya
server/
ms_
SASjs server
xplatform/
mx_
Runtime platform detection
fcmp/
,
lua/
,
ddl/
PROC FCMP functions, LUA wrappers, DDL
Use
mf_
macros when the macro returns a value usable in an expression; use
mp_
for procedural macros that generate code/statements.
文件夹前缀平台
base/
mf_
(函数式)、
mp_
(过程式)
所有平台
meta/
mm_
SAS 9元数据
metax/
mmx_
SAS 9元数据(依赖操作系统命令)
viya/
mv_
Viya
server/
ms_
SASjs server
xplatform/
mx_
运行时平台检测
fcmp/
lua/
ddl/
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.
mp_abort
(the deprecated
mf_abort
is retained for backwards compatibility — don't use it in new code),
mf_existds
,
mf_existvar
,
mf_existfileref
,
mf_getuser
,
mp_jsonout
(SAS datasets → JSON for
_webout
),
mp_ds2ddl
,
mp_hashdataset
. Platform-specific variants exist under
meta/
,
viya/
,
server/
and are selected at compile time by the CLI.
在编写新宏之前,请先检查库中是否已有现成的宏——常见工具类宏已存在,例如
mp_abort
(已弃用的
mf_abort
为兼容旧版本保留,请勿在新代码中使用)、
mf_existds
mf_existvar
mf_existfileref
mf_getuser
mp_jsonout
(将SAS数据集转换为JSON输出到
_webout
)、
mp_ds2ddl
mp_hashdataset
。特定平台的变体宏位于
meta/
viya/
server/
目录下,由CLI在编译时自动选择。

Aborting safely

安全终止程序

Never invoke
%mp_abort
from inside an
%if/%else
block — as a procedural macro, the macro processor can continue executing statements after it before the abort takes effect. Use the
iftrue=
condition parameter instead:
sas
%mp_abort(iftrue= (&syscc ne 0)
  ,mac=&_program
  ,msg=%str(Something went wrong)
)
When
%mp_abort
is called from within a
%include
block, SAS cannot exit cleanly (e.g. to
_webout
). Call
%mp_abort(mode=INCLUDE)
after the include (OUTSIDE any macro wrapper) — it checks
work.mp_abort_errds
for an abort status:
sas
%mp_abort(mode=INCLUDE)
Note:
%include
s inside macros should be performed with
%mp_include()
so the
_SYSINCLUDEFILEDEVICE
indicator is set and the abort dataset (
work.mp_abort_errds
) is passed back to the calling program.
切勿在
%if/%else
块内调用
%mp_abort
——作为过程式宏,宏处理器可能在终止生效前继续执行后续语句。请改用
iftrue=
条件参数:
sas
%mp_abort(iftrue= (&syscc ne 0)
  ,mac=&_program
  ,msg=%str(Something went wrong)
)
当在
%include
块内调用
%mp_abort
时,SAS无法干净退出(例如输出到
_webout
)。请在
%include
之后(宏包装器外部)调用
%mp_abort(mode=INCLUDE)
——它会检查
work.mp_abort_errds
中的终止状态:
sas
%mp_abort(mode=INCLUDE)
注意:宏内部的
%include
操作应使用
%mp_include()
,这样会设置
_SYSINCLUDEFILEDEVICE
标识,并将终止数据集(
work.mp_abort_errds
)传递回调用程序。

Lint and build

代码检查与构建

  • Run
    sasjs lint
    after every change; do not consider work done until it passes
  • NEVER bump the version in
    package.json
    (semantic-release handles it)
  • Do NOT edit generated files by hand:
    all.sas
    ,
    mc_*.sas
    , the
    lua/
    wrappers, and
    sasjsbuild/
    outputs are produced by the CI build
  • Markdown files: never hard-wrap; one paragraph per line
  • 每次修改后运行
    sasjs lint
    ;未通过检查则视为工作未完成
  • 禁止手动修改
    package.json
    中的版本号(由semantic-release自动处理)
  • 禁止手动编辑生成文件:
    all.sas
    mc_*.sas
    lua/
    目录下的包装器以及
    sasjsbuild/
    目录下的输出文件均由CI构建生成
  • Markdown文件:禁止手动换行;每段内容单独占一行