BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
larsc
Obsidian | Level 7

Hello everyone,

 

New SAS user and beginner programmer in general, so this may be a very basic question and the terminology might be a bit off. I am currently trying to create a JSON file which is going to be posted to an API. This is all done within DI Studio. A new requirement to the JSON-file format have me somewhat confused as to what the best solution would be. Below is a sample of the desired output of the JSON file.

 

[

{
     "Store":{
               "StoreCode":"Aldi"
                  },
     "Date": "2021-02-08",
     "CustomerCount": 11000,
     "CustomerSpending": 800
}

]

 

The issue for me is creating this "nested" key-value pair ("StoreCode":"Aldi") part which is highlighted in Bold. Currently I've tried to work around this using the following code:

 

substr(compress('{"StoreCode": ' || '"' || Store|| '"' || '}'), 1, 25)

 

This is obviously not a good solution as this will come through as a string. Is there a way for SAS to create nested key-value pairs like in the sample above?

1 ACCEPTED SOLUTION

Accepted Solutions
BillM_SAS
SAS Employee

Since you are new to SAS may I say welcome to the SAS Communities. May I suggest you look at the JSON procedure for producing the JSON file. I assume that will be available to you in DI Studio. I have not used DI Studio.

 

It will take some extra work to produce the hierarchical JSON file with the JSON procedure. Since you did not post the data set from which you are creating the JSON, I cannot give you a working example creating the JSON file. I suggest you take a look at the following posts to get an idea of how this can be done with the JSON procedure:
https://communities.sas.com/t5/Developers/Exporting-Nested-Tables-to-JSON/m-p/717112#M1122

https://communities.sas.com/t5/SAS-Canada-Discussion-Forum/Formattting-JSON/m-p/688562#M224

 

 

View solution in original post

2 REPLIES 2
BillM_SAS
SAS Employee

Since you are new to SAS may I say welcome to the SAS Communities. May I suggest you look at the JSON procedure for producing the JSON file. I assume that will be available to you in DI Studio. I have not used DI Studio.

 

It will take some extra work to produce the hierarchical JSON file with the JSON procedure. Since you did not post the data set from which you are creating the JSON, I cannot give you a working example creating the JSON file. I suggest you take a look at the following posts to get an idea of how this can be done with the JSON procedure:
https://communities.sas.com/t5/Developers/Exporting-Nested-Tables-to-JSON/m-p/717112#M1122

https://communities.sas.com/t5/SAS-Canada-Discussion-Forum/Formattting-JSON/m-p/688562#M224

 

 

larsc
Obsidian | Level 7

Thank you @BillM_SAS, worked like a charm

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 530 views
  • 0 likes
  • 2 in conversation