BookmarkSubscribeRSS Feed
learn_SAS_23
Pyrite | Level 9

Hello Team, 

 

am reading data from Json file , where its contents are dynamic  as shown in below format 

the first record has all attributes , where as second record has only few attributes.

 

[
  {
    "id": 0,
    "name": "Nora",
    "city": "New Orleans",
    "age": 55,
    "friends": [
      {
        "name": "Emma",
        "hobbies": [ "Calligraphy", "Television", "Music" ]
      },
      {
        "name": "Lucas",
        "hobbies": [ "Yoga", "Playing Cards" ]
      }
    ]
  },
  {
    "id": 1,
    "name": "Mia",
  },
  
]
	libname APIJSON JSON fileref=jsonout;

	proc datasets lib=APIJSON; quit;

i would like to concatenate all datasets in json library  as per Json model schema and load null values for optional attributes or data sets

 

In this example , friends data set is optional and city , age attributes are optional

3 REPLIES 3
SASJedi
Ammonite | Level 13

Do you really mean concatenate, or do you want the result of a join? I'd expect something like this would fit the bill:

proc sql;
select id, r.name, city, age, f.name, hobbies1, hobbies2, hobbies3  
	from apijson.root as r
	left join 
		  apijson.friends as f
		on r.ordinal_root=f.ordinal_root
	left join 
	  apijson.Friends_hobbies as h
		on h.ordinal_friends=f.ordinal_friends
	order by ID
;
quit;

Result:

id name city age name hobbies1 hobbies2 hobbies3
0 Nora New Orleans 55 Lucas Yoga Playing Cards  
0 Nora New Orleans 55 Emma Calligraphy Television Music
1 Mia   .        
Check out my Jedi SAS Tricks for SAS Users
learn_SAS_23
Pyrite | Level 9

as mentioned , the json attributes are dynamic like in this example friends data set is dynamic 

learn_SAS_23
Pyrite | Level 9
which means for few records we will get friends data and for other records we wont't get as it is a optional field

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 960 views
  • 0 likes
  • 2 in conversation