BookmarkSubscribeRSS Feed
langalife
Calcite | Level 5

We are using SAS Decision Manager architecture (not cloud based), and mostly the underlying SAS Micro Analytics Server (MAS) to support high performance on-demand calculations, where data is fed in from another (non SAS) user system (via json), and the results passed back.    We want to send in some information via an array to a variable call total_mark, let the SAS program loop through the array, load it as separate items in a datagrid, and do calculations on the items in the array.  We are copying a previous application where this was done and which works, but replicating the same methodology on the new application, it seems it is not recognizing the array or contents at all. We built the new code in SAS Studio, and it is working, but the moment we deploy on SAS MAS, it doesn’t seem to recognize the array.  We would appreciate some guidance, please.

 

Case study:

Provide marks for a student as an input array.  Read in the values into a datagrid (for other downstream purposes which will not be shown), but also calculate the average mark to return as output value.

 

Sample SAS Code:

/*Calculation Code*/

proc ds2;

     /*Code published on MAS*/

     ds2_options sas;

 

     package array_test1/overwrite=yes;

           dcl package datagrid array_test();

           dcl varchar(64000) str3 out_str3;

           dcl double in_values x out_x total_mark average_mark;

           dcl int ip_iter max_count out_max_count;

 

           /*Method to create input data grid and calculate average*/

           method create_inputs_test(double in_values[500], in_out nvarchar str3, in_out int max_count, in_out double x, in_out double average_mark);

                x = in_values[1];

                put x;

                str3='[                                                                                                   

                     {"metadata":                                                                              

                     [                                                                                                              

                     {"in_values":"double"}                                                    

                     ]                                                              

                     },                                                                                  

                     {"data":                                                                                        

                     []                                                             

                     }                                                                               

                     ]';

                array_test.deserialize(str3);

                max_count = 0;

                total_mark = 0;

                average_mark = 0;

                do ip_iter=1 to dim(in_values);

                     if (in_values[ip_iter] <> null) then

                           do;

                                array_test.rowAdd();

                                array_test.setdouble('in_values', ip_iter, in_values[ip_iter]);

                                max_count = max_count + 1;

                                total_mark=sum(total_mark, in_values[ip_iter]);

                           end;

                end;

                average_mark = total_mark/max_count;

 

                str3 = array_test.serialize();

                put 'input str3:' str3;

                put 'max_count:' max_count;

           end;

 

           /*Main method called and executed by web_services call*/

           method end_to_end_model_run(double in_values[500], in_out nvarchar out_str3, in_out int out_max_count, in_out double out_x, in_out double out_av_mark);

                create_inputs_test(in_values, str3, max_count, x, average_mark);

                out_str3 = str3;

                out_max_count = max_count;

                out_x = x;

                out_av_mark = average_mark;

           end;

 

     endpackage;

     /*end of deployed SAS MAS code*/

run;

 

/*SAS Testing code*/

table _null_;

     method init();

           dcl package array_test1 testarray();

           dcl double in_values[500] x out_x out_av_mark;

           dcl varchar(64000) out_str3;

           dcl int dim_in out_max_count;

 

           /*test values - array of 3 test scores*/

           in_values := (56,72,87.8);

           dim_in = dim(in_values);

           put 'dim_in' dim_in;

 

           /*Call main execution method*/

           testarray.end_to_end_model_run(in_values, out_str3, out_max_count, out_x, out_av_mark);

 

           /*Disply output results expected on the front-end system*/

           put 'str3' out_str3;

           put 'out_max_count' out_max_count;

           put 'out_x' out_x;

           put 'out_average_mark' out_av_mark;

     end;

run;

 

quit;

 

 

OUTPUT in SAS Studio Logs, which is correct and what we expect:

max_count: 3

str3 [{"metadata":[{"IN_VALUES":"decimal"}]},{"data":[[56],[72],[87.8]]}]

out_max_count 3

out_x 56

out_average_mark 71.9333333333333

 

Note:  “Str3” shows the datagrid as it is created and the individual datagrid items. 

 

When running in SAS MAS, however, the ‘in-values’ array looks like it might be interpreted as being empty (filled with nulls), which is our main problem.  In order to display what SAS MAS sees, we adapted the condition in the code published in SAS MAS to get a view of how the array in SAS MAS.  The condition change in the code is as follows:

From:

do ip_iter=1 to dim(in_values);

                     if (in_values[ip_iter] <> null) then

 

To (basically forcing it to look at first 10 items): 

do ip_iter=1 to 10;

                     if (ip_iter] <= 10) then

 

The json output from SAS MAS is as follows (via postman) shows that the ‘in-values’ array has 10 null items as content for some reason, which then influences all further calculations:

 

    "output": [

        {

            "name": "out_str3",

            "value": "[{\"metadata\":[{\"IN_VALUES\":\"decimal\"}]},{\"data\":[[null],[null],[null],[null],[null],[null],[null],[null],[null],[null]]}]"

        },

        {

            "name": "out_max_count",

            "value": 10

        },

        {

            "name": "out_x",

            "value": null

        },

        {

            "name": "out_av_mark",

            "value": 0.0

        }

    ]

}

 

(Accompanying postman json input: 

{

    "inputs": [

        {

            "name": "in_values",

            "value": [

                56,

                72,

                87.8

            ]

        }

    ]

}

 

Thus: 

We’re not sure why the array is not recognized in SAS MAS when it is working in SAS Studio.  As said, we also compared the methodology with another working application and don’t know why this one won’t work.  We have rebuilt it with several other views, but none of the new applications work to get the array recognized.  Thanks for your assistance in advance.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 357 views
  • 0 likes
  • 1 in conversation