Home > Blockchain >  Proc json produces extra blanks after applying a format
Proc json produces extra blanks after applying a format

Time:12-08

I would like to export a sas dataset to json. I need to apply the commax10.1 format to make it suitable for some language versions. The problem is that the fmtnumeric option applies the format correctly but inserts extra blanks inside the quotes. I have tried trimblanks and other options but have not been able to get rid of them. How to delete the empty blanks inside the quotes? Note: I would like the values to remain inside the quotes

In addition, is it possible to replace the null values with “” ?

Sample data:

data testdata_;
input var1 var2 var3;
format _all_ commax10.1;
datalines;
 3.1582 0.3 1.8
 21 . .
 1.2 4.5 6.4
;
proc json out = 'G:\test.json' pretty fmtnumeric nosastags trimblanks keys;
export testdata_;
run;

In the link you can see what the output looks like.

enter image description here

CodePudding user response:

trimblanks only trims trailing blanks. The format itself is adding leading blanks, and proc json has no option that I am aware of to remove leading blanks.

One option would be to convert all of your values to strings, then export.

data testdata_;
    input var1 var2 var3;
    format _all_ commax10.1;

    array var[*] var1-var3;
    array varc[3] $;

    do i = 1 to dim(var);
        varc[i] = strip(compress(put(var[i], commax10.1), '.') );
    end;

    keep varc:;

    datalines;
3.1582 0.3 1.8
21 . .
1.2 4.5 6.4
;

This would be a great feature request. I recommend posting this to the SASWare Ballot Ideas or contact Tech Support and let them know of this issue.

  • Related