BookmarkSubscribeRSS Feed
learn_SAS_23
Quartz | Level 8

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
SAS Super FREQ

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
Quartz | Level 8

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

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

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