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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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