SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
John2020
Calcite | Level 5

I have JSON where the values have a forward slash in them such as "Amt w/total"

 

{
   "data" : [
     { "a" : 1 , "Amt w/total" : 10 },
    ]
}

So when the map is created it looks like

 

{
    "NAME": "Amt_w_total",
    "TYPE": "NUMERIC",
    "PATH": "/root/data/Amt w/total"
}

This reads in as all missing because I assume it's treating the / as a separator in the path and looking for values of "Amt w" and "total".

 

Is there any way to tell it the slash is part of the value?

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Just a long shot:

Maybe SAS expects the / to be escaped, as in 

 Amt w\/total

and gets confused?

Does the map work if you correct the map?

 

 

John2020
Calcite | Level 5
Doesn't seem to. I've tried backlashes, doubling up the slashes, and adding single quotes. If the values can be escaped, I haven't figured out the magic character yet.
Tom
Super User Tom
Super User

Ask SAS support for help.

It is definitely valid to have / in key value. 

https://www.w3schools.com/js/js_json_objects.asp#:~:text=Keys%20must%20be%20strings%2C%20and,is%20se...

You can try it yourself: 

 https://www.w3schools.com/js/tryit.asp?filename=tryjson_object_loop

 

Not sure where to look for what is valid in that path syntax that the map files are using.

Tom
Super User Tom
Super User

If you cannot get it to work then perhaps your can made a modified version of the data that changes that value.  Perhaps using unix tool like sed or even just reading the file in a datastep and using TRANWRD().

filename json temp;
options parmcards=json;
parcards4;
{
   "data" : [
     { "a" : 1 , "Amt w/total" : 10 }
    ]
}
;;;;

filename fixed temp;
data _null_;
  infile json;
  file fixed;
  input;
  _infile_=tranwrd(_infile_,'"Amt w/total"','"Amt w_total"');
run;

filename map temp;
libname json json map=map automap=reuse;

proc print data=json.data; 
run;
       ordinal_    ordinal_         Amt_w_
Obs      root        data      a     total

 1         1           1       1      10

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1450 views
  • 0 likes
  • 3 in conversation