All rights reserved. 687411_0313. SAS® 9.4 JSON Procedure Tip Sheet.
Exporting a JSON File. Using Default Options. This example exports data from
Sashelp.
Exporting a JSON File ® File Using Default Options Exporting a JSON SAS 9.4 JSON Using Default Options Exporting JSON File All This example exports dataafrom Exporting a Sashelp.Class. JSON Exporting Exporting aaJSON JSON File FileFile PROC JSON default options are enabled. Using Default Options This example exports data from Sashelp.Class. Using Default Options All Using Default Default Options PROCUsing JSON default optionsOptions are enabled.
The output begins with an open JSON object ThisThis example exports datadata from Sashelp.Class. All container ({) as theexports top-level container. Following example from Sashelp.Class. The output begins with an open JSON objectAll This This example example exports exports data data from from Sashelp.Class. Sashelp.Class. All All PROC JSON default options are enabled. the top-level container, the SAS export version and PROC default options are enabled. container ({) as the top-level Following PROC PROC JSON JSONJSON default default options options are arecontainer. enabled. enabled. exported SAS data set name the export defaultversion SAS and the top-level container, theisSAS The The output begins with an open JSON object metadata. A JSON array container is opened ([) to output begins with an open JSON SAS data isJSON the default SAS The Theexported output outputbegins begins with withset an anname open openJSON object objectobject container ({) as the top-level container. Following collect the observations as a list of values. Each container ({) as the top-level container. Following metadata. A JSON array container is opened ([) to container container({) ({)asasthe thetop-level top-levelcontainer. container.Following Following thecollect top-level container, theasSAS export version and observation is then exported as a nested JSON the top-level container, the SAS export version the observations a list of values. Each the thetop-level top-levelcontainer, container,the theSAS SASexport exportversion versionand and and exported SAS data set name is the default SAS object ({ }). PROC JSON writes the data as a single exported SAS data set name is the default SAS observation is then exported as default adefault nested JSON exported exported SAS SASdata data set set name name isisthe the SAS SAS metadata. A}).JSON array container is opened ([) to line. Each observation consists ofiskey-value pairs metadata. A JSON array container is opened ([) to object ({A PROC JSON writes data as atoto single metadata. metadata. A JSON JSON array array container container isthe opened opened ([) ([) collect the observations as a list of values. Each for the variable names and values. Trailing blanks collect the observations as a list of values. Each line.the Each observation ofvalues. key-value collect collect the observations observations asasconsists aalist listofofvalues. Each Eachpairs observation is then exported as aas nested JSON are removed the end ofasascharacter data. observation isexported then exported aTrailing nested JSON for the variable names and values. blanks observation observation isisfrom then then exported aanested nested JSON JSONThe object ({ }). PROC JSON writes thecontainer data as aas single object ({ }). PROC JSON writes the data a single output file ends by closing the array (]) are removed from the end of character data. The object object({({}). }).PROC PROCJSON JSONwrites writesthe thedata dataasasaasingle single line. Each observation consists of key-value pairs line. Each observation consists of key-value pairs andoutput the top-level container. file ends by closing the array container line. line. Each Each observation observation consists consists ofofkey-value key-value pairs pairs(]) forthe the variable names and values. Trailing blanks for thetop-level variable names and values. Trailing blanks and the container. for for the variable variable names names and and values. values. Trailing Trailing blanks blanks areremoved removed from the end of character data. TheThe are removed from theofofend of character data. proc json out='C:\DefaultOutput.json'; are are removed from from the the end end character character data. data. The The output file ends by closing the array container output file ends by closing the array container export sashelp.class (where=(age=12)); output output file file ends endsout='C:\DefaultOutput.json'; by byclosing closingthe thearray arraycontainer container(]) (])(]) (]) proc json run; andthe the top-level container. and the top-level container.(where=(age=12)); export sashelp.class and and the top-level top-level container. container. run;
{"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam procjson jsonout='C:\DefaultOutput.json'; out='C:\DefaultOutput.json'; proc json out='C:\DefaultOutput.json'; proc proc json out='C:\DefaultOutput.json'; e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh export sashelp.class (where=(age=12)); export sashelp.class (where=(age=12)); {"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam export export sashelp.class sashelp.class (where=(age=12)); (where=(age=12)); t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh run; run; run; run; 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": :12,"Height":59,"Weight":99.5},{"Name":"Louise","S 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name :12,"Height":59,"Weight":99.5},{"Name":"Louise","S {"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam {"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam {"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam {"SASJSONExport":"1.0","SASTableData+CLASS":[{"Nam ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh e":"James","Sex":"M","Age":12,"Height":57.3,"Weigh t":128}]} ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": t":83},{"Name":"Jane","Sex":"F","Age":12,"Height": t":128}]} 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" 59.8,"Weight":84.5},{"Name":"John","Sex":"M","Age" :12,"Height":59,"Weight":99.5},{"Name":"Louise","S :12,"Height":59,"Weight":99.5},{"Name":"Louise","S :12,"Height":59,"Weight":99.5},{"Name":"Louise","S :12,"Height":59,"Weight":99.5},{"Name":"Louise","S Note: The actual JSON output file is a single line of ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name ex":"F","Age":12,"Height":56.3,"Weight":77},{"Name Note: The actual JSON output file is a single line of text. ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh ":"Robert","Sex":"M","Age":12,"Height":64.8,"Weigh t":128}]} text. t":128}]} t":128}]} t":128}]}
The actual JSON output is a single line Note:Note: Theactual actual JSON output file is asingle single line of of Note: Note: The The actual JSON JSON output output file file isisfile aasingle line line ofof text. text. text. text.
Controlling JSON Output With Options Controlling JSON Output Procedure Tip Sheet With Options Controlling Output This example exports dataJSON from Sashelp. Class and Controlling JSON Output Controlling Controlling JSON JSON Output Output uses options to control the JSON output. With Options This example exports data from Sashelp. Class and With Options With Options Options uses options With to control the JSON output.
1 The PRETTY option creates a more readable ThisThis example data Sashelp. Class format by usingexports indention tofrom illustrate the JSONand example exports data from Sashelp. 1 example The PRETTY option creates a more readable This This example exports exports data datathe from from Sashelp. Sashelp. Class ClassClass and and and uses options to control JSON output. container structure. 2 The WHERE= data set option uses by options toindention control the JSON output. format using to illustrate the JSON uses uses options options toto control control the theJSON JSON output. output. specifies conditions to select observations from the container structure. 2 The WHERE= data set option 1 The PRETTY option creates a more readable SAS data set. 3 The NOKEYS option removes SAS 1 The PRETTY option creates a more readable specifies conditions to selectaamore observations from the The PRETTY optioncreates creates morereadable readable 11The PRETTY option format by using indention to illustrate thethe JSON variable names, by including NOKEYS in the format by using to option illustrate JSON SAS data set.indention 3and Theindention NOKEYS SAS format by using indention illustrate theremoves JSON format by using totoillustrate the JSON container structure. 2each The WHERE= data setset option EXPORT statement, selected observation is container structure. 2 The WHERE= data variable names, and by including NOKEYS in the containerstructure. structure.22The TheWHERE= WHERE=data dataset setoption optionoption container specifies conditions toeach select observations from the exported as aconditions list of in an array container. specifies to select observations from EXPORT statement, selected observation specifies conditions select observations fromthe theis the specifies conditions totovalues select observations from SAS data set. 3 The NOKEYS option removes SAS 4 The NOSASTAGS option removes SAS metadata, SAS data set. 3 The NOKEYS option removes exported listNOKEYS of values in an array container. SAS dataset. set.as33aThe The NOKEYS option removes SAS SAS SAS data option removes SAS variable names, and by including NOKEYS in the and by including NOSASTAGS in the EXPORT variable names, and by including NOKEYS 4 Thenames, NOSASTAGS option removes SAS variable names, andby byincluding including NOKEYS thein the variable and NOKEYS ininmetadata, the EXPORT statement, each selected observation is statement, the top-level container is a JSON array. EXPORT statement, each selected observation and by including NOSASTAGS in the EXPORT EXPORTstatement, statement,each eachselected selectedobservation observationisis is EXPORT exported as a list of values in an array container. exported asof aoflist of values in aniscontainer. array container. statement, the top-level container a JSON array. exported list values inan anarray array container. exported asasaalist values in 4 The NOSASTAGS option removes SAS metadata, 4NOSASTAGS The option removes SAS metadata, proc jsonNOSASTAGS out='C:\ControlOutput.json' The NOSASTAGS option removes SAS metadata, 44The option removes SAS metadata, and by including in EXPORT and by including NOSASTAGS in the EXPORT pretty; 1NOSASTAGS and by including NOSASTAGS thethe EXPORT and by including NOSASTAGS ininthe EXPORT proc json out='C:\ControlOutput.json' export sashelp.class (where=(age=12)) 2 statement, top-level container aisJSON array. statement, the top-level container a JSON array. pretty; 1 statement, thethe top-level container JSON array. statement, the top-level container isisaaisJSON array. / nokeys 3 nosastags; 4 export sashelp.class (where=(age=12)) 2 run; / nokeys 3 nosastags; 4 proc json out='C:\ControlOutput.json' proc json out='C:\ControlOutput.json' proc proc json json out='C:\ControlOutput.json' out='C:\ControlOutput.json' run; [ pretty; 1 1 pretty; pretty; 1 pretty; 1 [ export sashelp.class (where=(age=12)) export sashelp.class (where=(age=12)) [export export sashelp.class (where=(age=12)) 22 2 2 sashelp.class (where=(age=12)) "James", ["M", / nokeys 3 nosastags; / nokeys 3 nosastags; / 33 nosastags; 44 4 4 / nokeys nokeys nosastags; "James", 12, run; run; run; run; "M", 57.3, 12, 83 [ [[ [ ], 57.3, [ [[ [[ 83 "James", "James", ], "James", "James", "Jane", "M", "M", [ "M", "M", "F", 12, 12, "Jane", 12, 12, 12, 57.3, 57.3, "F", 57.3, 57.3, 59.8, 83 12,83 8384.5 83 ], ], 59.8, ],], ], [ 84.5 [ [[ [ "Jane", ], "Jane", "Jane", "Jane", "John", [ "F","F", "F", "F", "M", "John", 12, 12, 12, 12, 12, 59.8, "M", 59.8, 59.8, 59.8, 59, 12,84.5 84.5 84.5 84.5 99.5 ], 59, ], ],], ], [ [[ [[ 99.5 "John", ], "John", "John", "John", "Louise", [ "M","M", "M", "M", "F", 12, "Louise", 12,12, 12, 12, 59, "F", 59,59, 59, 56.3, 99.5 12, 99.5 99.5 99.5 77 ], ], ], 56.3, ], [ ], 77 [[ [ "Louise", ["Louise", ], "Louise", "Louise", "F", ["Robert", "F", "F", "F", 12, "M", "Robert", 12,12, 12, 56.3, 12, "M", 56.3, 56.3, 56.3, 12,77 7764.8, 77 77 ], 128 64.8, ], ], ], [ [[ ][ 128 "Robert", ] "Robert", ] "Robert", "Robert", "M", ] "M", "M", "M",12, 12, 12,12, 64.8, 64.8, 64.8, 64.8, 128 128 128128 ] ]] ] ] ]] ]
JSON Containers JSON Containers JSON object container {…}
begins with a left brace ({) and ends with a right JSON object JSON containerContainers {…} brace Ana object container key-value JSON Containers begins(}). with left brace ({) andcollects ends with a right JSON JSON Containers Containers pairs that are written as pairs of names and values. A brace (}). An object container collects key-value JSON object container {…} value can be any of the supported JSON data types, JSON object container {…} pairs that are written as pairs of names and values. A JSON JSON object object container container {…} {…} begins with a left brace ({) and ends with a right an object, or an array. Each key (name) is followed begins abrace left brace ({)ends andwith ends with a types, right value canaawith be any of the supported JSON data begins begins with with left left brace ({) ({) and and ends with a a right right brace (}). An object container collects key-value by aobject, colon and the value. key-value pairs (}). An object container collects anbrace or anthen array. Each keyThe (name) iskey-value followed brace brace (}). (}).that An An object object container container collects collects key-value key-value pairs are written as pairs of names and values. A are separated by a comma. pairs that are written as pairs of names and values. bythat a colon and then value. The key-value pairs pairs pairs that are arewritten written as asthe pairs pairs ofofnames names and andvalues. values. AA A value can be any of the supported JSON data types, value can beby of the supported JSON data types, arecan separated athe comma. value value can be be any any ofany the supported supported JSON JSON data dataistypes, types, anan object, ororof an array. Each key (name) followed JSON array container […] object, an array. Each key (name) is followed an anobject, object,ororan anarray. array.Each Eachkey key(name) (name)isisfollowed followed byby a colon and then the value. The key-value pairs begins with a left bracket ([) and ends with a right a array colon and then the value. The key-value pairs container […] by byaJSON acolon colon and andthen then the the value. value. The Thekey-value key-value pairs pairs are separated by a comma. bracket (]). An array container collects a list of are separated by a comma. with aaleft bracket ([) and ends with a right are arebegins separated separated by by acomma. comma. values as a list collects of valuesa list without bracketthat (]). are An written array container of JSON array container […] names. A value can be any of the supported JSON JSON array container […] values that are written as a list of values without JSON JSONarray arraycontainer container[…] […] begins with a object, left bracket ([) and ends with aaright data types, an or an array. Values are begins with a left bracket ([) and ends with names. A value can be any of the supported JSON begins beginswith withaaleft leftbracket bracket([) ([)and andends endswith withaaright right right bracket (]). An array container collects aare list separated by aAn comma. bracket (]). array container collects aof listofof data types, an object, or an array. Values bracket bracket (]). (]).An An array array container container collects collects aalist listof values that are written as a list of values without values that are written as a list of values without separated bywritten a comma. values values that thatare are written asasaalist listofofvalues valueswithout without names. AAvalue can bebeof any ofof the JSON names. value can thesupported supported JSON names. names. AAvalue value can can be be any any ofany the the supported supported JSON JSON Container Tips data types, an object, or an array. Values are data types, an object, or an array. Values are data datatypes, types,an anobject, object, ororan anarray. array.Values Values are Container Tipsare separated separated bya acomma. comma. separated separated byThe aaby comma. comma. by top-level container can include any of containers. container number The top-level containerEach can include anycan Container Tips Container then nest containers toEach anTips arbitrary depth. number of containers. container can Container Container Tips Tips then nest containers to an arbitrary depth. The container can any Objects Thetop-level top-level caninclude include any require acontainer listcan of include key-value pairs, The The top-level top-level container container can include any any number of containers. Each container can number of containers. Each container can number Objects require a list of key-value pairs, where value can be JSON datacan types, an number ofofthe containers. containers. Each Each container container can thennest nest containers to arbitrary depth. then containers toarbitrary ananarbitrary depth. where the value can be JSON data types, an object, or an array. then then nest nest containers containers totoan an arbitrary depth. depth. object, or an array. Arrays Objects require aof key-value pairs, Objects require list ofof key-value pairs, Objects Objects require require aalist listaof key-value key-value pairs, pairs, are merely alist list of values, objects, where the value can be JSON data types, an where the value can be JSON data types, where Arrays are merely a JSON list of data values, objects, where the thevalue value can canbe be JSON datatypes, types, an an an or arrays. object, or an array. object, or an array. or arrays. object, object, ororan anarray. array. WRITE VALUES statement(s) for an object Arrays aremerely merely aof list values, objects, Arrays are aof list ofofvalues, objects, WRITE VALUES statement(s) for an Arrays Arrays are aremust merely merely aalist list values, values, objects, objects, result in an even number of or arrays. or arrays. object must result in an even number of ororarrays. arrays. values, and the key portion of the key-value values, andbethe key portion of the key-value pair must a string. pair WRITE VALUES statement(s) foran an must be a string. WRITE VALUES statement(s) for WRITE WRITE VALUES VALUES statement(s) statement(s) for foran an object must result in an even number object must result an even number object object must must result result ininan anineven even number number ofof ofof values, and the key portion of the key-value values, and the key portion ofkey-value the key-value values, values, and andthe thekey keyportion portion ofofthe the key-value pairmust must bea astring. string. pair be pair pair must must be be a a string. string. For complete information, refer to the For complete referatto the SAS 9.4information, documentation SAS 9.4 documentation at support.sas.com/documentation. support.sas.com/documentation. Forcomplete complete information, refer the For Forcomplete complete information, information, refer referrefer to tothe the For information, totothe SAS 9.4 documentation at SAS SASSAS 9.4 9.4documentation documentation atat at 9.4 documentation support.sas.com/documentation. support.sas.com/documentation. support.sas.com/documentation. support.sas.com/documentation. SAS Institute Inc. +1 919 677 8000
World Headquarters www.sas.com/offices
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies. Copyright © 2011, SAS Institute Inc. All rights reserved. 687411_0313
SAS®® 9.4 SAS 9.4 JSON Procedure ® ® ® ® JSON Procedure SAS SAS9.4 9.49.4 SAS SAS Tip Sheet Tip Sheet JSON Procedure JSON JSON JSON Procedure Procedure This tip sheet places frequently used information in Tip Sheet Tip one place, on one sheet of paper, soinformation you don’t have Tip Tip Sheet Sheet This tip sheet places frequently used in to search throughout the documentation. This tip
one place, on one sheet of paper, so you don’t have presents SAS the 9.4 documentation. information for This the JSON tosheet search throughout tip This tip sheet places frequently used information in This tip sheet places frequently procedure. sheet presents SAS 9.4 information for the JSON This Thistip tipsheet sheetplaces placesfrequently frequentlyused usedinformation informationinin in one on one of sodon’t you have don’t have oneplace, place, onsheet one sheet sheet of paper, one oneprocedure. place, place, on onone one sheet of ofpaper, paper, so soyou you don’t have have totosearch throughout the documentation. search throughout the documentation. Thisdata tip throughout PROC JSON reads data from a tip SAS totosearch search throughout the thedocumentation. documentation. This This tip sheet presents SAS 9.4 information for sheet presents SAS 9.4 information the JSON set andJSON writes it todata an for external file in PROC reads from SAS data sheet sheetpresents presents SAS SAS 9.4 9.4 information information for the theaJSON JSON procedure. procedure. set and 1writes it to an external file in representation. JSON procedure. procedure. JSON1 representation. You PROC JSON reads adata SAS data PROC data PROC canJSON control thefrom exported data with PROC JSON JSON reads readsreads data data from afrom aSAS SAS data setwrites andcontrol writes itthat file inand set and writes itthe to an external set You can exported data with several options remove content setand and writes it it to to an an external external file file in in 11 1JSON 1 representation. representation. JSON several options that remove content and representation. representation. JSON JSON affect the format. affect the format. PROC You can control datathat with You can control the exported You can can control control the the exported exported data datawith with You JSON provides statements several options that several options that remove content several PROC JSON provides statements that several options options that remove remove content contentdata and and toand enable youthat to write additional the affect the format. affect the format. enable you to write additional data to the affect affect the the format. format. external file and control JSON containers. external file and control JSON containers. PROC PROC JSON provides statements PROC JSON provides statements that PROC JSON JSON provides provides statements statements that that that enable you to write additional data enable you to additional write additional data to the the enable enable you youtoto write write additional data datatoto the theto external file and control JSON containers. external filecontrol and control containers. external external file fileand and control JSON JSONJSON containers. containers.
1
JavaScript Object Notation (JSON) is a text-based, open JavaScriptdata Object Notation is for a text-based, open data standard format that is(JSON) designed human-readable standard data format is designed for human-readable data interchange. JSON that is based on a subset of the JavaScript interchange. JSON is based a subset of the JavaScript programming language andonuses JavaScript syntax for describing programming and uses JavaScript syntax for describing 1 data objects. language 11 Object Notation (JSON) is a text-based, 1 JavaScript JavaScript JavaScript Object ObjectObject Notation Notation (JSON) (JSON) isisaatext-based, text-based, open open open data objects. JavaScript Notation (JSON) is a text-based, open standard data that format that is designed for human-readable standard standard data dataformat format thatisisdesigned designed for forhuman-readable human-readable data data data standard data format that is designed for human-readable data interchange. JSON is based on a subset of the JavaScript interchange. interchange. JSON JSONis isbased based onaasubset subset ofthe theJavaScript JavaScript interchange. JSON ison based on a of subset of the JavaScript programming language and uses JavaScript syntax for describing programming programming language languageand anduses usesJavaScript JavaScriptsyntax syntaxfor fordescribing describing programming data objects. language and uses JavaScript syntax for describing data dataobjects. objects. data objects. 1
SAS 9.4 Statement Statement Options Options ®
PROC PROC JSON JSON Syntax Syntax PROC PROC JSONJSON OUT=fileref OUT=fileref | 'external-file' | 'external-file' PROC PROC JSON JSON Syntax Syntax ; ; PROC PROC JSON JSON OUT=fileref OUT=fileref | 'external-file' | 'external-file' EXPORT EXPORT SAS-data-set SAS-data-set ; ; ; ; EXPORT EXPORT SAS-data-set SAS-data-set WRITE WRITE VALUES VALUES value(s) value(s) ; ; ; ; WRITE WRITE OPEN OPEN type;value(s) type; WRITE WRITE VALUES VALUES value(s) ; ; WRITE WRITE CLOSE; CLOSE; WRITE WRITE OPEN OPEN type; type; WRITE WRITE CLOSE; CLOSE;
Argument Argument Description Description
OUT=fileref OUT=fileref | Argument 'external-file' | 'external-file' Argument Description Description identifies identifies the JSON the JSON outputoutput file with fileeither with either a SASa SAS fileref fileref that is that assigned is assigned with the with FILENAME the FILENAME OUT=fileref OUT=fileref | 'external-file' | 'external-file' statement statement orthethe or physical theoutput physical location location ofwith theof JSON the JSON identifies identifies the JSON JSON output file file with either either a SAS a SAS output output file. file. fileref fileref thatthat is assigned is assigned withwith the the FILENAME FILENAME
statement statement or the or the physical physical location location of the of the JSON JSON output output file.file. specifies specifies statement statement options options that control that control the resulting the resulting JSON JSON output. output. (Statement (Statement options options are listed are listed in the in the next panel.) next panel.) specifies specifies statement statement options options thatthat control control the the resulting resulting
JSON JSON output. output. (Statement (Statement options options are are listed listed in the in the SAS-data-set SAS-data-set nextnext panel.) panel.) identifies identifies the SAS the data SASset data to set be exported to be exported with either with either aSAS-data-set oneaor onetwo-level or two-level SAS name SAS name (library (library and member and member SAS-data-set name). name). identifies identifies the the SASSAS datadata set to setbe to exported be exported withwith either either
a onea oneor two-level or two-level SASSAS name name (library (library andand member member name). name). specifies specifies SAS data SASset data options set options that apply that apply to the to input the input SAS data SAS set. data set. specifies specifies SASSAS datadata set options set options thatthat apply apply to the to the input input value(s) value(s) SASSAS datadata set.set. specifies specifies one orone more or more valuesvalues to write to write to the to JSON the JSON output output file. Separate file. Separate values values with a with blank a blank space. space. A A value(s) value(s) value value can be can a string, be a string, a number, a number, the Boolean the Boolean value value specifies specifies oneone or more or more values values to write to write to the to the JSON JSON TRUE TRUE orfile. FALSE, or FALSE, or NULL. orvalues NULL. output output file. Separate Separate values withwith a blank a blank space. space. A A value value cancan be abestring, a string, a number, a number, the the Boolean Boolean value value type type TRUE TRUE or FALSE, or FALSE, or NULL. or NULL. specifies specifies the type theof type JSON of JSON container container to explicitly to explicitly open as open either as either ARRAY ARRAY or OBJECT. or OBJECT. typetype specifies specifies the the typetype of JSON of JSON container container to explicitly to explicitly open open as either as either ARRAY ARRAY or OBJECT. or OBJECT.
JSON Procedure Tip Sheet Creating Creating and and Controlling Controlling
12 12 FMTCHARACTER FMTCHARACTER | NOFMTCHARACTER | NOFMTCHARACTER Statement Statement Options Options determines determines whether whether to apply to apply an associated an associated character character SAS format. SAS format. 12 12 FMTCHARACTER FMTCHARACTER | NOFMTCHARACTER | NOFMTCHARACTER
determines determines whether whether to apply to apply an associated an associated 1 character 2 character 12 FMTDATETIME FMTDATETIME | NOFMTDATETIME SASSAS format. format. | NOFMTDATETIME determines determines whether whether to apply to apply an associated an associated date, date, time, or time, datetime or datetime SAS| NOFMTDATETIME format. SAS format. 12 12 FMTDATETIME FMTDATETIME | NOFMTDATETIME
determines determines whether whether to apply to apply an associated an associated 1 2 date, 1 2date, FMTNUMERIC FMTNUMERIC |SAS NOFMTNUMERIC | NOFMTNUMERIC time, time, or datetime or datetime SAS format. format. determines determines whether whether to apply to apply an associated an associated numeric numeric SAS format SAS format (excluding (excluding time, date, time, and datetime and 1 2 datetime 12 FMTNUMERIC FMTNUMERIC | NOFMTNUMERIC | date, NOFMTNUMERIC SAS formats). SAS formats). determines determines whether whether to apply to apply an associated an associated numeric numeric SASSAS format format (excluding (excluding date, time, time, andand datetime datetime 12 1 2 date, KEYS KEYS | NOKEYS | NOKEYS SASSAS formats). formats). determines determines whether whether to include to include or suppress or suppress SAS SAS variable variable names as keys for values. 1 as 2 for 1keys 2 values. KEYS KEYS |names NOKEYS | NOKEYS
determines determines whether whether to include to1 include or suppress SASSAS 1or suppress PRETTY PRETTY | NOPRETTY | as NOPRETTY variable variable names names keys as keys for for values. values. determines determines how tohow format to format the JSON the JSON output. output. PRETTY PRETTY uses indention. uses indention. NOPRETTY writes writes outputoutput 1 1 NOPRETTY PRETTY PRETTY | NOPRETTY | NOPRETTY asdetermines a single as a single line of line text. of text. determines howhow to format to format the the JSON JSON output. output. PRETTY PRETTY usesuses indention. indention. NOPRETTY writes writes output output 1 2NOPRETTY 12 SASTAGS SASTAGS |line NOSASTAGS as aassingle a single line of| NOSASTAGS text. of text. determines determines whether whether to include to include or suppress or suppress top-level top-level tags, the tags, object the| NOSASTAGS object top-level top-level container, and export the export 1 2container, 1 2 and the SASTAGS SASTAGS | NOSASTAGS metadata. metadata. determines determines whether whether to include to include or suppress or suppress top-level top-level
tags,tags, the the object object top-level andand the the export export 1 top-level 2 3 1 2container, 3 container, SCAN SCAN | NOSCAN | NOSCAN metadata. metadata. determines determines whether whether PROCPROC JSONJSON scans scans and encodes and encodes input input strings. strings. 1 2 31 2 3 SCAN SCAN | NOSCAN | NOSCAN determines determines whether whether PROC JSON scans scans andand encodes encodes 2 PROC 2 JSON TABLENAME='name' TABLENAME='name' input input strings. strings. specifies specifies an alternate an alternate suffixsuffix for thefor SASTableData the SASTableData top-level top-level tag. tag. 2 2 TABLENAME='name' TABLENAME='name'
specifies specifies an alternate an alternate suffix suffix for for the the SASTableData 1SASTableData 23 123 TRIMBLANKS TRIMBLANKS | NOTRIMBLANKS top-level top-level tag.tag.| NOTRIMBLANKS determines determines whether whether to remove to remove or retain or retain trailing trailing blanks blanks in character in character string string values. values. 1 2 31 2 3 TRIMBLANKS TRIMBLANKS | NOTRIMBLANKS | NOTRIMBLANKS
determines determines whether whether to remove to remove or retain or retain trailing trailing - blanks Option - Option supported supported in: in:values. blanks in character in character string string values. 1 1 PROC PROC JSONJSON statement statement 2 2 EXPORT EXPORT statement statement - Option - Option supported in: in: 3 supported 3 VALUES VALUES statement statement 1WRITE 1 WRITE PROC PROC JSON JSON statement statement - Default - Default option keywords keywords appear appear in in bold. 2 2 option EXPORT EXPORT statement statement bold. 3
3 WRITE WRITE VALUES VALUES statement statement - Default - Default option option keywords keywords appear appear in bold. in bold.
Containers Containers Creating Creating and and Controlling Controlling As theAs first thestatement first statement after the after PROC the PROC JSONJSON Containers Containers statement: statement:
As the As the firstfirst statement statement afterafter the the PROC PROC JSON JSON statement: EXPORT EXPORT with default with default options options enabled enabled statement: implicitly implicitly opensopens an object an object top-level top-level container, implicitly implicitly opens opens an array an enabled array container, EXPORT EXPORT withwith default default options options enabled container container toopens collect to an collect observations observations as a list as of a list of implicitly implicitly opens object an object top-level top-level values, values, and then and exports then exports each observation each observation container, container, implicitly implicitly opens opens an array an array ascontainer a nested as a nested object. object. container to collect to collect observations observations as aaslist a list of of {metadata {metadata [{obs1},{obs2}…]} values, values, and[{obs1},{obs2}…]} and thenthen exports exports eacheach observation observation
as aasnested a nested object. object. EXPORT {metadata EXPORT with NOKEYS with NOKEYS enabled enabled [{obs1},{obs2}…]} {metadata [{obs1},{obs2}…]} implicitly implicitly opensopens an object an object top- level top- level container, container, implicitly implicitly opens opens an array an array EXPORT NOKEYS enabled EXPORT withwith NOKEYS enabled container container to collect to collect observations observations as alevel list as of a list of implicitly opens an object implicitly opens an object top-toplevel values, values, and then and exports then exports each observation each observation container, implicitly opens an array container, implicitly opens an array ascontainer a nested as a nested array. array. container to collect observations a list to collect observations as aaslist of of {metadata {metadata [[obs1],[obs2]…]} values, and exports observation values, and[[obs1],[obs2]…]} thenthen exports eacheach observation a nested array. as aasnested array. EXPORT {metadata EXPORT with NOSASTAGS with NOSASTAGS enabled enabled [[obs1],[obs2]…]} {metadata [[obs1],[obs2]…]} implicitly implicitly opensopens an array an array top-level top-level container, and and exports then exports eachenabled each EXPORT EXPORT with NOSASTAGS enabled container, withthen NOSASTAGS observation observation as a nested as a nested object. object. implicitly opens an array top-level implicitly opens an array top-level [{obs1},{obs2}…] [{obs1},{obs2}…] container, exports container, andand thenthen exports eacheach
observation a nested object. observation as aasnested object. EXPORT [{obs1},{obs2}…] EXPORT with NOSASTAGS with NOSASTAGS and and [{obs1},{obs2}…] NOKEYS NOKEYS enabled enabled implicitly implicitly opensopens an an array top-level top-level container, container, and then and then exports EXPORT EXPORT NOSASTAGS and array withwith NOSASTAGS andexports each observation each observation as aimplicitly nested as a nested array. array. NOKEYS enabled implicitly opens NOKEYS enabled opens an an [[obs1],[obs2]…] [[obs1],[obs2]…] array top-level container, exports array top-level container, andand thenthen exports observation a nested array. eacheach observation as aasnested array. WRITE [[obs1],[obs2]…] WRITE VALUES VALUES implicitly implicitly opensopens an an [[obs1],[obs2]…] objectobject top-level top-level container. container.
WRITE VALUES implicitly opens WRITE VALUES implicitly opens an an WRITE WRITE OPEN OPEN OBJECT OBJECT explicitly explicitly opensopens an object, an object, object top-level container. object top-level container. whichwhich you must you explicitly must explicitly close close with WRITE with WRITE CLOSE. CLOSE. WRITE OPEN OBJECT explicitly opens an object, WRITE OPEN OBJECT explicitly opens an object, which must explicitly close WRITE which youyou must explicitly close withwith WRITE WRITE WRITE OPENOPEN ARRAY ARRAY explicitly explicitly opensopens an array, an array, CLOSE. CLOSE. whichwhich you must you explicitly must explicitly close close with WRITE with WRITE CLOSE. CLOSE. WRITE OPEN ARRAY explicitly opens an array, WRITE OPEN ARRAY explicitly opens an array, which must explicitly close WRITE which youyou must explicitly close withwith WRITE CLOSE. CLOSE.
Exporting Exporting Data, Data, Writing Writing Arbitrary Arbitrary JSON JSON Output, Output, Exporting Exporting Data, Data, andand Creating Creating Containers Containers Writing Writing Arbitrary Arbitrary JSON JSON Output, Output, This example Thisand example exports exports a subset a subset of Sashelp.Class, of Sashelp.Class, and Creating Creating Containers Containers
writeswrites additional additional valuesvalues to the to JSON the JSON outputoutput file, and file, and controls controls and nests and JSON nests JSON containers. containers. ThisThis example example exports exports a subset a subset of Sashelp.Class, of Sashelp.Class,
writes writes additional additional values values to the to the JSON JSON output output file,file, andand 1 WRITE VALUES implicitly an object 1controls WRITE VALUES implicitly opensopens an object top- topcontrols and and nests nests JSON JSON containers. containers. level container and writes a value the top-level level container and writes a value to theto top-level container. 2 WRITE OPEN ARRAY container. 2 WRITE OPEN ARRAY explicitly 1 WRITE 1 WRITE VALUES VALUES implicitly implicitly opens opens an object anexplicitly object top-topopens an array container. 3 WRITE VALUES opens an array container. 3 WRITE VALUES writeswrites level level container container andand writes writes a value a value to the to the top-level top-level a value open array container. 4explicitly WRITE acontainer. value to the2to open array container. 4 WRITE OPENOPEN container. WRITE 2the WRITE OPEN OPEN ARRAY ARRAY explicitly OBJECT explicitly object container that is OBJECT opensopens an object container that iswrites opens opens anexplicitly array an array container. container. 3 WRITE 3 an WRITE VALUES VALUES writes nested in the array container. 5 EXPORT exports a nested in the array container. 5 EXPORT exports a a value a value to the to the open open array array container. container. 4 WRITE 4 WRITE OPEN OPEN subset of the Sashelp.Class data set to the open subset of the Sashelp.Class data set to the open OBJECT OBJECT explicitly explicitly opens opens an object an object container container thatthat is is object implicitly opens an array container object container, implicitly opens an array container nested nested in the incontainer, the array array container. container. 5 EXPORT 5 EXPORT exports exports a a to of collect theSashelp.Class observations asset a list of the values, tosubset collect the asdata a list of values, and subset the ofobservations the Sashelp.Class data to set the to open openand then nests the exported observation as an object. 6 then nests the exported observation as an object. 6 object object container, container, implicitly implicitly opens opens an array an array container container WRITE CLOSE explicitly closes the open object WRITE CLOSE explicitly closes the open object to collect to collect the the observations observations as aaslist a list of values, of values, andand container. 7 WRITE CLOSE explicitly container. 7the WRITE CLOSE explicitly the 6 the thenthen nests nests the exported exported observation observation as closes an as object. ancloses object. 6 openCLOSE array container. The object top-level container open array container. The object top-level container WRITE WRITE CLOSE explicitly explicitly closes closes the the open open object object is implicitly closed. iscontainer. implicitly container. 7closed. WRITE 7 WRITE CLOSE CLOSE explicitly explicitly closes closes the the open open array array container. container. TheThe object object top-level top-level container container
proc proc json json out='C:\Arbitrary.json' out='C:\Arbitrary.json' pretty; pretty; is implicitly is implicitly closed. closed. write values 'Age 'Age 11'; 11'; 1 write values 1 writewrite open open array; 2 array; 2 write values 'Girls'; 3 write values 'Girls'; 3 proc proc json json out='C:\Arbitrary.json' out='C:\Arbitrary.json' pretty; pretty; write open object; 4 11'; write open object; 41 1 write write values values 'Age 'Age 11'; export sashelp.class(where=((sex='F') export sashelp.class(where=((sex='F') write write open open array; array; 2 2 and (age=11))); 5 and (age=11))); write write values values 'Girls'; 'Girls'; 35 3 write close; 6 object; write close; 6 4 4 write write open open object; write close; 7 write close; 7 export export sashelp.class(where=((sex='F') sashelp.class(where=((sex='F') run; run; andand (age=11))); (age=11))); 5 5 write write close; close; 6 6 write close; close; 7 7 { { write "Age 11": "Age [11": [ run; run;
"Girls", "Girls", { { { "SASJSONExport": "1.0 PRETTY", "SASJSONExport": "1.0 PRETTY", "Age"Age 11":11": [ [ "SASTableData+CLASS": [ "SASTableData+CLASS": [ "Girls", "Girls", { { { { "Name": "Joyce", "Name": "Joyce", "SASJSONExport": "SASJSONExport": "1.0"1.0 PRETTY", PRETTY", "Sex":"Sex": "F", "F", "SASTableData+CLASS": "SASTableData+CLASS": [ [ "Age":"Age": 11, 11, { { "Height": 51.3, 51.3, "Height": "Name": "Name": "Joyce", "Joyce", "Weight": 50.5 50.5 "Weight": "Sex": "Sex": "F","F", } } "Age": "Age": 11, 11, ] ] "Height": "Height": 51.3, 51.3, } } "Weight": "Weight": 50.550.5 ] ] } } } } ] ] } } ] ] } } {