Export
defaults to outputting a dataset as an array of objects of name:value pairs. With NOKEYS
the construct is an array of arrays, with the inner array being an array of values.
In order to get a single array of values for a column, you can transpose the column into a single rowed data set and export that. You will not have to OPEN ARRAY
before EXPORT
.
data have;
do row = 1 to 10;
userid = uuidgen();
age = 19 + row;
output;
end;
run;
* transpose a single column into a single row data set;
proc transpose data=have out=have_1_row(drop=_name_);
var userid;
run;
filename users "C:\temp\users.json" ;
proc json out = users nosastags pretty;
WRITE VALUES "schema";
WRITE VALUES "EMAIL_SHA26";
WRITE VALUES "data";
EXPORT have_1_row / NOKEYS;
RUN;
Yields json
{
"schema": "EMAIL_SHA26",
"data": [
"6ebd89fa-b6bc-4c14-b094-43792d202ad7",
"ec53dd59-1290-47d7-b437-0c754349434c",
"17332882-58ca-4c09-a599-2048d58460d0",
"d5b57a19-ff73-4deb-bfc7-62ebc19d719e",
"9d2758b2-e128-45df-8589-99cd7204c1ab",
"a13bcba7-742f-4a01-bd56-dc12f4190d3e",
"5f853bf3-9597-4c94-9b57-a54d3de190c3",
"0edbd2d8-bd5d-46be-aaa7-ac208df4ba62",
"07347e73-7efa-4e9c-8242-5a9c85f07b56",
"03976b1b-513f-41ee-92d5-d23c8d3d4918"
]
}
For the case of wanting to EXPORT more than one column as an array of values, consider using DOSUBL
to invoke a macro that side-runs the transposition and generates the single row data set used in a macro code generated EXPORT
statement:
%macro transpose_column(data=, column=, out=);
%* generate code that will transpose a single column into a single row data set;
proc transpose data=&data out=&out(keep=col:);
var &column;
run;
%mend;
%macro export_column_as_array (data=, column=);
%local rc out;
%let out = _%sysfunc(monotonic());
%* Invoke DOSUBL to side-run macro generated proc transpose code;
%let rc = %sysfunc(
DOSUBL(
%transpose_column(data=&data, column=&column, out=&out)
)
);
%* use the output data set created by the side-run code;
WRITE VALUES "&column";
EXPORT &out / NOKEYS;
%mend;
data have;
do row = 1 to 10;
userid = uuidgen();
age = 19 + row;
date = today() - row;
output;
end;
format date yymmdd10.;
run;
filename users "C:\temp\users.json" ;
options mprint mtrace;
proc json out = users nosastags pretty;
WRITE VALUES "schema";
WRITE VALUES "EMAIL_SHA26";
%export_column_as_array(data=have,column=userid);
%export_column_as_array(data=have,column=age);
%export_column_as_array(data=have,column=date);
run;
quit;