sas_dataset_json is a comprehensive SAS macro-package that enables seamless bidirectional conversion between SAS datasets and the CDISC-compliant Dataset-JSON v1.1 format.
Developed with clinical data interchange and regulatory-ready workflows in mind, this package empowers users to both export SAS datasets into the Dataset-JSON representation and import Dataset-JSON files back into SAS, preserving metadata, formats, and extended attributes.
https://www.docswell.com/s/6484025/5WW7G4-2025-05-26-023206
Exports a SAS dataset to Dataset-JSON format (version 1.1).
- To convert a SAS dataset into a structured Dataset-JSON format(version 1.1) .
- Automatically extracts metadata such as labels, data types, formats,and extended attributes if defined.
- Generates a metadata-rich datasetJSON with customizable elements.
outpath : Path to output directory (default: WORK directory).
library : Library reference for input dataset (default: WORK).
dataset : Name of the input dataset (required).
pretty : Whether to pretty-print the JSON (Y/N, default: Y).
originator : Organization or system creating the file (optional).
fileOID : File OID to uniquely identify the JSON (optional).
studyOID : Study OID used in the Define-XML reference (optional).
metaDataVersionOID : Metadata version OID (optional).
sourceSystem_name : Source system name (default: SAS on &SYSSCPL.).
sourceSystem_version : Source system version (default: from &SYSVLONG).
- Automatically detects and prioritizes extended attributes for variables.
- Captures dataset-level metadata such as label and last modified date.
- Outputs structured "columns" and "rows" sections per dataset-JSON v1.1.0.
- Requires access to
sashelp.vxattr,sashelp.vcolumn, andsashelp.vtable. - Uses PROC JSON, PROC SQL, PROC CONTENTS, and extended attribute inspection.
- Extended variable attributes (label, type, format, etc.) override defaults.
- All variables are output with detailed metadata including data types, display formats, and lengths.
- Output file is saved as "&outpath.&dataset..json".
%m_sas_to_json1_1(outpath =/project/json_out,
library = adam,
dataset = adsl,
pretty = Y); %m_sas_to_json1_1(
outpath=/project/json_out,
library=SDTM,
dataset=AE,
pretty=Y,
originator=ABC Pharma,
fileOID=http://example.org/studyXYZ/define,
studyOID=XYZ-123,
metaDataVersionOID=MDV.XYZ.1.0,
sourceSystem_name=SAS 9.4,
sourceSystem_version=9.4M7
);proc datasets nolist;
modify adsl;
xattr add ds originator="X corp."
fileOID="www.cdisc.org/StudyMSGv2/1/Define-XML_2.1.0/2024-11-11/"
studyOID="XX001-001"
metaDataVersionOID="MDV.MSGv2.0.SDTMIG.3.4.SDTM.2.0"
sourceSystem_name="SASxxxx"
sourceSystem_version="9.4xxxx"
;
xattr add var
STUDYID (label="Study Identifier"
dataType="string"
length=8
keySequence=1)
USUBJID (label="Unique Subject Identifier"
dataType="string"
length=7
keySequence=2)
RFSTDTC (label="Subject Reference Start Date/Time"
dataType="date")
AGE (label="Age"
dataType="integer"
length=2)
TRTSDT (label="Date of First Exposure to Treatment"
dataType="date"
targetDataType="integer"
displayFormat="E8601DA.") ;
;
run;
quit;
%m_sas_to_json1_1(outpath = /project/json_out,
library = WORK,
dataset = adsl,
pretty = Y);Imports CDISC-compliant dataset-JSON v1.1 into a SAS dataset, reconstructing structure and metadata including extended attributes.
- Reads dataset-JSON using the FILENAME and JSON LIBNAME engine
- Extracts "root", "columns", and "rows" objects from JSON
- Dynamically generates:
- LABEL, FORMAT, and RENAME statements
- INPUT conversion logic for ISO8601 date/datetime types
- Automatically applies:
- Dataset-level metadata via PROC DATASETS and XATTR
- Variable-level extended attributes such as:
- dataType
- targetDataType
- displayFormat
- keySequence
- length
- LABEL, FORMAT, and RENAME statements
- Provides warnings for unsupported data types (e.g., decimal)
inpath : Path to the folder containing the dataset-JSON file
ds : SAS dataset name to create (derived from the file name)
Requirements:
- SAS 9.4M5 or later (for JSON LIBNAME engine and extended attributes)
- Input JSON must follow the dataset-JSON v1.1 specification
Notes:
- "decimal" targetDataType is not natively supported in SAS;
values are read as numeric using the best. format with a warning
- Date and datetime values are parsed using E8601DA. and E8601DT. formats
- Extended metadata attributes are added using PROC DATASETS/XATTR
%m_json1_1_to_sas(inpath=/data/definejson, ds=AE);Exports a SAS dataset to NDJSON (Representation of Dataset-JSON) format (version 1.1). This macro is designed to support clinical data interchange by generating
- To convert a SAS dataset into a structured NDJSON format(subset of Dataset-JSON version 1.1) .
- Automatically extracts metadata such as labels, data types, formats, and extended attributes if defined.
- Generates a metadata-rich datasetJSON with customizable elements.
outpath : Path to output directory (default: WORK directory).
library : Library reference for input dataset (default: WORK).
dataset : Name of the input dataset (required).
originator : Organization or system creating the file (optional).
fileOID : File OID to uniquely identify the JSON (optional).
studyOID : Study OID used in the Define-XML reference (optional).
metaDataVersionOID : Metadata version OID (optional).
sourceSystem_name : Source system name (default: SAS on &SYSSCPL.).
sourceSystem_version : Source system version (default: from &SYSVLONG).]]
- Automatically detects and prioritizes extended attributes for variables.
- Captures dataset-level metadata such as label and last modified date.
- Outputs structured "columns" and rows part sections per dataset-JSON v1.1.0.
- Requires access to
sashelp.vxattr,sashelp.vcolumn, andsashelp.vtable. - Uses PROC JSON, PROC SQL, PROC CONTENTS, and extended attribute inspection.
- Extended variable attributes (label, type, format, etc.) override defaults.
- All variables are output with detailed metadata including data types,
display formats, and lengths.
- Output file is saved as "&outpath.\&dataset..ndjson".
%m_sas_to_ndjson1_1(outpath =/project/json_out,
library = adam,
dataset = adsl,
); %m_sas_to_ndjson1_1(
outpath=/project/json_out,
library=SDTM,
dataset=AE,
originator=ABC Pharma,
fileOID=http://example.org/studyXYZ/define,
studyOID=XYZ-123,
metaDataVersionOID=MDV.XYZ.1.0,
sourceSystem_name=SAS 9.4,
sourceSystem_version=9.4M7
);proc datasets nolist;
modify adsl;
xattr add ds originator="X corp."
fileOID="www.cdisc.org/StudyMSGv2/1/Define-XML_2.1.0/2024-11-11/"
studyOID="XX001-001"
metaDataVersionOID="MDV.MSGv2.0.SDTMIG.3.4.SDTM.2.0"
sourceSystem_name="SASxxxx"
sourceSystem_version="9.4xxxx"
;
xattr add var
STUDYID (label="Study Identifier"
dataType="string"
length=8
keySequence=1)
USUBJID (label="Unique Subject Identifier"
dataType="string"
length=7
keySequence=2)
RFSTDTC (label="Subject Reference Start Date/Time"
dataType="date")
AGE (label="Age"
dataType="integer"
length=2)
TRTSDT (label="Date of First Exposure to Treatment"
dataType="date"
targetDataType="integer"
displayFormat="E8601DA.");
;
run;
quit;
%m_sas_to_ndjson1_1(outpath = /project/json_out,
library = WORK,
dataset = adsl);Imports CDISC-compliant NDJSON (Representation of Dataset-JSON) format (version 1.1) into a SAS dataset, reconstructing structure and metadata including extended attributes.
- Convert ndjson to dataset-json once internally
- Reads dataset-JSON using the FILENAME and JSON LIBNAME engine
- Extracts "root", "columns", and "rows" objects from JSON
- Dynamically generates:
- LABEL, FORMAT, and RENAME statements
- INPUT conversion logic for ISO8601 date/datetime types
- Automatically applies:
- Dataset-level metadata via PROC DATASETS and XATTR
- Variable-level extended attributes such as:
- dataType
- targetDataType
- displayFormat
- keySequence
- length
- Provides warnings for unsupported data types (e.g., decimal)
inpath : Path to the folder containing the dataset-JSON file
ds : SAS dataset name to create (derived from the file name)
- SAS 9.4M5 or later (for JSON LIBNAME engine and extended attributes)
- Input JSON must follow the dataset-JSON v1.1 specification
- "decimal" targetDataType is not natively supported in SAS;
- values are read as numeric using the
best.format with a warning - Date and datetime values are parsed using
E8601DA.andE8601DT.formats - Extended metadata attributes are added using PROC DATASETS/XATTR
%m_ndjson1_1_to_sas(inpath=/data/definejson, ds=AE);- Nakaya Ryo — contributed the %m_ndjson1_1_to_sas_stream
Imports a CDISC Dataset-JSON 1.1 NDJSON file into a SAS dataset while processing the data portion in chunks. The first physical line is treated as the Dataset-JSON metadata line. Each remaining physical line is treated as one NDJSON data line.
inpath : Directory containing <ds>.ndjson
ds : Input file stem and output SAS dataset name
outlib : Output SAS library (default: WORK)
chunksize: Number of NDJSON data lines processed per chunk (default: 10000)
obs : Optional maximum number of data lines to read from the beginning.
If omitted, all data lines are read.
where : Optional SAS expression evaluated after conversion, for example
%str(SEXN = 1 and AGE >= 65)
keep : Optional SAS variable list retained in the completed dataset, for
example USUBJID PARAMCD AVAL or %str(USUBJID PARAM:)
- SAS 9.4M5 or later
- Dataset-JSON 1.1 NDJSON representation
- The first line contains root/columns metadata and each subsequent line contains a JSON row array
- CHUNKSIZE counts physical NDJSON data lines, not necessarily observations.
- OBS counts data lines only; the first metadata line is not included. When OBS is specified, lines after that limit are not scanned or parsed.
- WHERE reduces the records written to the output dataset. It does not reduce the amount of input read or JSON parsed.
- KEEP is applied after WHERE in each chunk. A variable used only by WHERE therefore does not need to be included in KEEP.
- The output dataset is replaced only after all chunks complete.
%m_ndjson1_1_to_sas_stream(
inpath=C:\data,
ds=ADSL,
outlib=OUTLIB,
chunksize=10000,
obs=1000,
where=%str(SEXN = 1),
keep=USUBJID AGE SEX
);0.3.0(24September2026) updated logical record length in %m_ndjson1_1_to_sas,
added a new macro %m_ndjson1_1_to_sas_stream(Contributed - Nakaya Ryo)
0.2.1(24Auguat2025):Fixed a bug in m_sas_to_json1_1 and m_sas_to_ndjson1_1 where reconversion (sas → json → sas) failed if non-ISO formats were used for numeric date, datetime, or time values.
0.2.0(13Auguat2025):Bug Fix.
0.1.3(23Jun2025): Support NDJSON, add %m_sas_to_ndjson1_1 and %m_ndjson1_1_to_sas
%m_sas_to_json1_1--Apply the e8601DT format to the LastModifiedDateTime.
0.1.2(25May2025): %m_sas_to_json1_1--Modified to not output data attributes with empty definitions.
0.1.1(23May2025): Add %m_json1_1_to_sas
0.1.0(22May2025): Initial version
The package is built on top of SAS Packages Framework(SPF) developed by Bartosz Jablonski.
For more information about the framework, see SAS Packages Framework.
You can also find more SAS Packages (SASPacs) in the SAS Packages Archive(SASPAC).
First, create a directory for your packages and assign a packages fileref to it.
filename packages "\path\to\your\packages";Secondly, enable the SAS Packages Framework. (If you don't have SAS Packages Framework installed, follow the instruction in SPF documentation to install SAS Packages Framework.)
%include packages(SPFinit.sas)Install SAS package you want to use with the SPF's %installPackage() macro.
-
For packages located in SAS Packages Archive(SASPAC) run:
%installPackage(packageName)
-
For packages located in PharmaForest run:
%installPackage(packageName, mirror=PharmaForest)
-
For packages located at some network location run:
%installPackage(packageName, sourcePath=https://some/internet/location/for/packages)
(e.g.
%installPackage(ABC, sourcePath=https://github.com/SomeRepo/ABC/raw/main/))
Load SAS package you want to use with the SPF's %loadPackage() macro.
%loadPackage(packageName)