8月 252020
 

Analytics is playing an increasingly strategic role in the ongoing digital transformation of organizations today. However, to succeed and scale your digital transformation efforts, it is critical to enable analytics skills at all tiers of your organization. In a recent blog post covering 4 principles of analytics you cannot ignore, SAS COO Oliver Schabenberger articulated the importance of democratizing analytics. By scaling your analytics efforts beyond traditional data science teams and involving more people with strong business domain knowledge, you can gain more valuable insights and make more significant impacts.

SAS Viya was built from the ground up to fulfill this vision of democratizing analytics. At SAS, we believe analytics should be accessible to everyone. While SAS Viya offers tremendous support and will continue to be the tool of choice for many advanced users and programmers, it is also highly accessible for business analysts and insights team who prefer a more visual approach to analytics and insights discovery.

Self-service data management

First of all, SAS Viya makes it easy for anyone to ingest and prepare data without a single line of code. The integrated data preparation components within SAS Viya support ad-hoc, agile-oriented data management tasks where you can profile, cleanse, and join data easily and rapidly.

Automatically Generated Data Profiling Report

You can execute complex joins, create custom columns, and cleanse your data via a completely drag-and-drop interface. The automation built into SAS Viya eases the often tedious task of data profiling and data cleansing via automated data type identification and transform suggestions. In an area that can be both complex and intimidating, SAS Viya makes data management tasks easy and approachable, helping you to analyze more data and uncover more insights.

Data Join Using a Visual Interface

A visual approach supporting low-code and no-code programming

Speaking of no-code, SAS Viya’s visual approach and support extend deep into data exploration and advanced modeling. Not only can you quickly build charts such as histograms and box plots using a drag and drop interface, but you can also build complex machine learning models using algorithms such as decision trees and logistic regression on the same visual canvas.

Building a Decision Tree Model Using SAS Viya

By putting the appropriate guard rails and providing relevant and context-rich help for the user, SAS Viya empowers users to undertake data analysis using other advanced analytics techniques such as forecasting and correlation analysis. These techniques empower users to ask more complex questions and can potentially help uncover more actionable and valuable insights.

Correlation Analysis Using the Correlation Matrix within SAS Viya

Augmented analytics

Augmented analytics is an emerging area of analytics that leverages machine learning to streamline and automate the process of doing analytics and building machine learning models. SAS Viya leverages augmented analytics throughout the platform to automate various tasks. My favorite use of augmented analytics in SAS Viya, though, is the hyperparameters autotuning feature.

In machine learning, hyperparameters are parameters that you need to set before the learning processing can begin. They are only used during the training process and contribute significantly to the model training process. It can often be challenging to set the optimal hyperparameter settings, especially if you are not an experienced modeler. This is where SAS Viya can help by making building machine learning models easier for everyone one hyperparameter at a time.

Here is an example of using the SAS Viya autotuning feature to improve my decision tree model. Using the autotuning window, all I needed to do was tell SAS Viya how long I want the autotuning process to run for. It will then work its magic and determine the best hyperparameters to use, which, in this case, include the Maximum tree level and the number of Predictor bins. In most cases, you get a better model after coming back from getting a glass of water!

Hyperparameters Autotuning in SAS Viya

Under the hood, SAS Viya uses complex optimization techniques to try to find the best hyperparameter combinations to use all without you having to understand how it manages this impressive feat. I should add that hyperparameters autotuning is supported with many other algorithms in SAS Viya, and you have even more autotuning options when using it via the programmatic interface!

By leveraging a visually oriented framework and augmented analytics capabilities, SAS Viya is making analytics easier and machine learning models more accessible for everyone within an organization. For more on how SAS Viya enables everyone to ask more complex questions and uncover more valuable insights, check out my book Smart Data Discovery Using SAS® Viya®.

Analytics for everyone with SAS Viya was published on SAS Users.

8月 242020
 

I got a lot of feedback about my recent article about how to find roots of nonlinear functions by using the SOLVE function in PROC FCMP. A colleague asked how the FCMP procedure stores the functions. Specifically, why the OUTLIB= option on the PROC FCMP statement use a three-level syntax: OUTLIB=libref.DataSetName.PackageName. The three levels are a libref, a data set name, and a package name. The documentation is terse about what the third level (the package name) is used for and why it is important. This article describes how the FCMP-defined functions are stored, and how you can use the package name to call different versions of a function.

This article is my attempt to "reverse engineer" how PROC FCMP stores functions based on what I have read and observed. In addition to the FCMP documentation, I recommend reading Secosky (2007) and Eberhardt (2009). Feel free to add your own knowledge in the comments.

How FCMP functions are stored

I started writing about the capabilities of the FCMP procedure in 2012, but the procedure itself goes back to SAS 9.2. Modern versions of SAS store functions in an analytic store (which is read by using PROC ASTORE) or in an item store (which is read by using PROC PLM). But these binary storage formats had not yet been developed back in the pre-9.2 days. So PROC FCMP stores functions in a SAS data set. That means you can use PROC PRINT to investigate how PROC FCMP stores functions.

When you use the OUTLIB= option in PROC FCMP, you specify a three-level name: OUTLIB=libref.DataSetName.PackageName. The first two levels specify the name of a SAS data set. This data set is created if it doesn't exist, or it is modified if it already exists. The third level is used as a text field in a variable named _KEY_, which enables one data set to contain functions that belong to different packages. The package name becomes important if two packages define a function that has the same name.

To demonstrate, let's define some functions and store them in a data set named Work.MyFuncs. The following statements create two functions (A and B) that belong to the 'PROD' (for 'Production') package and one function (A) that belongs to the 'DEV' (for 'Development') package. Notice that both packages have a function named 'A'. The following statements define the functions and use PROC PRINT to display a portion of the Work.MyFuncs data set:

/* Store all functions in the data set WORK.MyFuncs */
/* Define functions in 'PROD' package */
proc fcmp outlib=work.MyFuncs.Prod;
   function A(x);
      return( x );      /* in the 'Prod' pkg, A(x) equals x */
   endsub;
   function B(x);
      return( x > 0 );
   endsub;
quit;
 
/* Define functions in 'DEV' package */
proc fcmp outlib=work.MyFuncs.Dev;
   function A(x);
      return( 2*x );    /* the 'Dev' pkg uses a different definition for A(x) */
   endsub;
quit;
 
proc print data=work.MyFuncs;
   var _Key_ Sequence Type Subtype Name;
run;

The output from PROC PRINT is shown. The data set contains 20 rows. I have put a red rectangle around rows 1–13 and another around rows 14–20. Each rectangle defines a package. The names of the packages are defined by the observations where Subtype='Package', which are highlighted in yellow. The Type, Subtype, and Name columns indicate how the FCMP statements that define the functions are stored in the data set. The _KEY_ column identifies which rows define which functions. There are other columns (not shown) that store the actual content of each function.

This output shows how the third level of the OUTLIB= option is used. The _KEY_ column records the package name and appends each function name ('A' or 'B') to the name of the package. So PROC FCMP knows that there are three stored functions whose full names are PROD.A, PROD.B, and DEV.A.

Calling a function from the DATA step

Since there are two functions called 'A', what happens if I call 'A' from a SAS DATA step? The answer is that the DATA step uses the most recent definition, which in this example is DEV.A. To alert you to the fact that calling 'A' is ambiguous, the SAS log displays a warning. You can also use the _DISPLAYLOC_ flag on the CMPLIB= system option to display the origin of each call to an FCMP function, as follows:

/* Tell the DATA step where to look for unresolved functions.
   The _DISPLAYLOC_ flag shows the full name for each call to an FCMP function */
options cmplib=(work.MyFuncs _DISPLAYLOC_); 
data Want;
   x = 1; y = A(x);   /* y is the result of the latest definition */
run;
 
proc print data=Want noobs; run;
WARNING: Function 'A' was defined in a previous package. 'A' in current
         package DEV will be used as default when the package name is not
         specified.
 
NOTE: Function 'A' loaded from work.MyFuncs.DEV.

The value of the X and Y variables make it clear that the function DEV.A was called (because A(x)=2*x in that definition). The WARNING and NOTE in the SAS log reinforce this fact.

Choosing which package to call

The WARNING in the previous section says that the current (most recent) package "will be used as default when the package name is not specified." This message seems to imply that you can somehow call PROD.A, which is the other stored function that is named 'A'. This is, in fact, true. The PROC FCMP documentation states, "to select a specific subroutine when there is ambiguity, use the package name and a period as the prefix to the subroutine name."

You cannot specify the package name directly in the DATA step, but you can specify the package name in an FCMP function. So, for example, you can define a function called 'ChooseA' that includes a flag that indicates which package to use. The following PROC FCMP statements define a function that will call either PROD.A or DEV.A, depending on the value of a parameter. This wrapper function can then be called in the DATA step:

/* In PROC FCMP, you can "dis-ambiguate" by using a two-level function name */
proc fcmp outlib=work.MyFuncs.Choose;
   function ChooseA(x, choice $);
      if upcase(choice)="DEV" then
        return( Dev.A(x) );
      else
        return( Prod.A(x) );
   endsub;
quit;
 
data WantChoice;
   x = 1;
   y_Dev  = ChooseA(x, "Dev");   /* call Dev.A */
   y_Prod = ChooseA(x, "Prod");  /* call Prod.A */
run;
 
proc print data=WantChoice noobs; run;

From the definitions of DEV.A and PROD.A, you can verify that each function was called correctly. Because the _DISPLAYLOC_ option is still active, the SAS log also indicates that each function was called.

Summary

This article was motivated by a question about how the FCMP procedure stores functions. The answer is that the OUTLIB= option on the PROC FCMP statement requires a libref, a data set name, and a package name. In most circumstances, you do not need to use the package name. The package name becomes important only if two different packages each support a function that has the same name. In that case, you can use the package name to disambiguate the function call.

Personally, I prefer to avoid having two packages that define the same function, but if you cannot avoid it, this trick shows you how to handle it. Eberhardt (2009, p. 15) discusses a related issue, which is how to call functions that are stored in two (or more) different data sets.

The post How does PROC FCMP store functions? appeared first on The DO Loop.

8月 212020
 

SAS Viya is an open analytics platform accessible from interfaces or various coding languages. REST API is one of the widely used interfaces. Multiple resources exist on how to access SAS Visual Analytics reports using SAS Viya REST API. For example Programmatically listing data sources in SAS Visual Analytics by my colleague Michael Drutar. His post shows how to list the data sources of VA reports. Also, in Using SAS Viya REST APIs to access images from SAS Visual Analytics, Joe Furbee demonstrates how to retrieve report images. In this post, I am going to show you how to get the path for SAS Visual Analytics reports using REST APIs.

Full API reference documentation for SAS REST APIs is on developer.sas.com. You can exercise REST APIs in several ways such as curl, browsers, browser plugins, or any other REST client. Here I am going to access the SAS Viya Visualization and Core Services REST API with SAS Code. The Visualization service APIs provide access for reports, report images, and report transforms. The Core Services APIs provides operations for resources like folders, files, authorization, and so on.

Composition of a report object

The chart below describes the object composition of VA reports, from an API perspective. We see the report object itself has metadata storing the report properties like id, name, creator, modified date, and links, etc. Each VA report object is identified uniquely by its ID in SAS Viya. The report content object, presented in either XML or JSON format, is stored separately from the report object. The report content object enumerates the data and image resources, generating visual elements such as graphs, tables, and images.

Reports API definition

Get a list of reports

Let's begin with a scenario of getting a list of reports. These reports may be returned from a search or a filter in Viya, or a list you've got at hand. (The SAS Viya support filter link has more information on using the filter.) Here I'm using a filter to get a list of reports named 'Report 2'. I use Proc HTTP to access the Reports API in the Visualization service with a 'GET' request and '/reports/reports?filter=eq(name,'Report 2')' in the URL. Note, the HEADERS of Proc HTTP need to be set properly to generate expected results. Below is a snippet for this.

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));
FILENAME rptFile TEMP ENCODING='UTF-8';
PROC HTTP METHOD = "GET" oauth_bearer=sas_services OUT = rptFile
      /* get a list of reports, say report name is 'Report 2' */
      URL = "&BASE_URI/reports/reports?filter=eq(name,'Report 2')";
      HEADERS "Accept" = "application/vnd.sas.collection+json"
               "Accept-Item" = "application/vnd.sas.summary+json";
RUN;
LIBNAME rptFile json;

The results of running the code above returns a list in the ITEMS table, in the rptFile json library. It returns about 10 reports with the same name of 'Report 2', each with a unique id.

ITEMS table report for 'Report2' query

Get the report content object of a VA report

Using the Reports API of the Visualization service, we can get the report content object of a VA report. As shown in the snippet below, by making a 'GET' request to the SAS Viya server followed by the '/reports/reports//content' in the URL, the report content object is retrieved.

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));
FILENAME rptFile TEMP ENCODING='UTF-8';
PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rptFile
           URL = "&BASE_URI/reports/reports/<report id>/content";
           HEADERS "Accept" = "application/vnd.sas.report.content+json";
RUN;
LIBNAME rptFile json;

In the output, we see the rptFile json library enumerates the data and image resources in the report content object. Below shows what I retrieved from a report content object.

Contents of rptFile json library

Notice the DATASOURCES_CASRESOURCE table, which Michael uses in Programmatically listing data sources in SAS Visual Analytics. You may explore more information in these tables if interested, such as report states, visual elements, etc. In this post, I won't dig further into the report content object.

Get the metadata of a report object

Next, I am going to get the metadata of a report object with its unique report id using the Reports API in the Visualization service. I use the 'GET' request and '/reports/reports/' in the URL. By runing the code snippet below, I get the metadata of the report object in the rptFile json library.

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));
FILENAME rptFile TEMP ENCODING='UTF-8';
PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rptFile
        URL = "&BASE_URI/reports/reports/cecac7d7-b957-412e-9709-a3fe504f00b1";
        HEADERS "Accept" = "application/vnd.sas.report+json";
RUN;
LIBNAME rptFile json;

Below is part of the ALLDATA table from the rptFile library. The table contains metadata of the report object, including its unique id, name, creator, creationTimeStamp, modifiedTimeStamp, links, and so on. But in the table, I can't find the folder location of the report object.

ALLDATA table from the rptFile library

Get the report object folder location

So far, I've retrieved most of the metadata info we are looking for, but not the report object folder location. All VA reports are put under the /SAS Content/ folder or its subfolders in SAS Viya. Yet, no such information exists in the report object or the report content object. How can I get the path of a VA report under the /SAS Content/ folder?

The answer is to use the Folders service on the Core Services API. Folders provide an organizational structure for SAS content as well as external content in Viya. The Folders object itself is a virtual container for other resources or folders, and it persists only the URI of resources managed by other services.

A folder object has two types of members: child and reference. Whereas resources can have references in multiple folders, they are restricted to being the child in a single folder. Resources like VA reports are added as child members of a folder, and the folder persists the URI of the is VA report. Thus, we get the folder reversely from the child report by looking for the ancestors of this report object.

By using the Folders API in Core services with a 'GET' request and '/folders/ancestors?childUri=' in the URL, the Proc HTTP code below gets the ancestors of the VA report before getting the full path.

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));
FILENAME fldFile TEMP ENCODING='UTF-8';
PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=fldFile
          URL = "&BASE_URI/folders/ancestors?childUri=/reports/reports/cecac7d7-b957-412e-9709-a3fe504f00b1";
          HEADERS "Accept" = "application/vnd.sas.content.folder.ancestor+json";
RUN;
LIBNAME fldFile json;

From the fldFile.ANCESTORS table, we see the metadata of the ancestor folders, including folder id, folder name, creator, type, and its parentFolderURI, etc. The screenshot below is part of the ANCESTORS table. Thus, the path of the specific report concatenates these subfolders to a full path of /SAS Content/NLS/Cindy/.

Folder path detailed in the ANCESTORS table

Get the path for VA reports

Now I have several reports, I need to go through the above steps repeatedly for each report. So, I wrote SAS code to handle these:

  1. Filter those reports named 'Report 2', using the reports API in Visualization service. Save the list of reports in the ds_rpts dataset. The results include metadata for report id, name, createdBy, CreatedAt, and LastModified.
  2. For each report in the ds_rpts data set, call the macro named 'save_VA_Report_Path(reportURI)'. The macro accesses the Folders API in Core Services, and saves the path for a given report back in the rptPath column of the ds_rpts data set.
  3. Print the list of reports with path and other metadata.

The code yields the following output:

List of reports with paths and metadata

You may access my code samples from GitHub and give it a try in your environment. I run the code with SAS Studio 5.2 and VA on SAS Viya 3.5. You may prefer to modify the filter condition as needed (such as createdBy, contains, or more from SAS Viya support filter).

Finally

The Reports API is one of many SAS Viya REST APIs. In this post, I've provided multiple discovery paths to follow. You can find more information about this and other APIs on the SAS Viya REST APIs page on the developers portal.

Discover Visual Analytics Report Paths with REST APIs was published on SAS Users.

8月 192020
 

No matter what your brand's level of marketing maturity is, SAS can help you move from data to insight to action with rich functionality for adaptive planning, journey activation and an embedded real-time decision engine – all fueled by powerful analytics and artificial intelligence (AI) capabilities. Let's begin with a [...]

SAS Customer Intelligence 360: Introduction to marketing data management was published on Customer Intelligence Blog.

8月 192020
 

Finding the root (or zero) of a nonlinear function is an important computational task. In the case of a one-variable function, you can use the SOLVE function in PROC FCMP to find roots of nonlinear functions in the DATA step. This article shows how to use the SOLVE function to find the roots of a user-defined function from the SAS DATA step.

Some ways to find the root of a nonlinear function in SAS

I have previously blogged about several ways to find the roots of nonlinear equations in SAS, including:

The DATA step does not have a built-in root-finding function, but you can implement one by using PROC FCMP.

PROC FCMP: Implement user-defined functions in SAS

PROC FCMP enables you to write user-defined functions that can be called from the DATA step and from SAS procedures that support DATA step programming statements (such as PROC NLIN, PROC NLMIXED, and PROC MCMC). To demonstrate finding the roots of a custom function, let's use the same function that I used to show how to find roots by using SAS/IML. The following statements use PROC FCMP to define a function (FUNC1) and to store the function to WORK.FUNCS. You must use the CMPLIB= system option to tell the DATA step to look in WORK.FUNCS for unknown functions. The DATA step evaluates the function for input arguments in the interval [-3, 3]. The SGPLOT procedure creates a graph of the function:

/* use PROC FCMP to create a user-defined function (FUNC1) */
proc fcmp outlib=work.funcs.Roots;
   function Func1(x);         /* create and store a user-defined function */
      return( exp(-x**2) - x**3 + 5*x +1 );
   endsub;
quit;
options cmplib=work.funcs;   /* DATA step will look here for unresolved functions */
 
data PlotIt;   
do x = -3 to 3 by 0.1;       /* evaluate function on [-3, 3] */
   y = Func1(x);
   output;
end;
run;
 
title "Graph of User-Defined Function";
proc sgplot data=PlotIt;
   series x=x y=y;
   refline 0 / axis=y;
   xaxis grid;
run;

From the graph, it appears that the function has three roots (zeros). The approximate locations of the roots are {-2.13, -0.38, 2.33}, as found in my previous article. The next section shows how to use the SOLVE function in PROC FCMP to find these roots.

Use the SOLVE function to find roots

The SOLVE function is not a DATA step function. It is a "special function" in PROC FCMP. According to the documentation for the special functions, "you cannot call these functions directly from the DATA step. To use these functions in a DATA step, you must wrap the special function inside another user-defined FCMP function." You can, however, call the SOLVE function directly from procedures such as NLIN, NLMIXED, and MCMC.

I was confused when I first read the documentation for the SOLVE function, so let me give an overview of the syntax. The SOLVE function enables you to find a value x such that f(x) = y0 for a "target value", y0. Thus, the SOLVE function enables you to find roots of the function g(x) = f(x) – y0. However, in this article, I will set y0 = 0 so that x will be a root of f.

Because the function might have multiple roots, you need to provide a guess (x0) that is close to the root. The SOLVE function will start with your initial guess and apply an iterative algorithm to obtain the root. Thus, you need to provide the following information to the SOLVE function:

  • The name of an FCMP function (such as "Func1") that will evaluate the function.
  • An initial guess, x0, that is near a root. (You can also provide convergence criteria that tells the iterative algorithm when it has found an approximate root.)
  • The parameters to the function. A missing value indicates the (one) parameter that you are solving for. For a function of one variable, you will specify a missing value for x, which tells the SOLVE function to solve for x. In general, a function can take multiple parameters, so use a missing value in the parameter list to indicate which parameter you are solving for.

The following SAS program defines a new FCMP function called Root_Func1. That function takes one argument, which is the initial guess for a root. Inside the function, the SOLVE function finds the root of the "Func1" function (defined earlier). If it was successful, it returns the root to the caller. To test the Root_Func1 function, I call it from a DATA step and pass in the values -2, 0, and +2. I obtained these guesses by looking at the graph of the Func1 function.

/* to call SOLVE in the DATA step, wrap it inside an FCMP function */
proc fcmp outlib=work.funcs.Roots;
   function Root_Func1(x0);
      array opts[5] init absconv relconv maxiter status; /* initialize to missing */
      opts[1] = x0;        /* opts[1] is the initial guess */
      z = solve("Func1",   /* name of function */
                opts,      /* initial condition, convergence criteria, and status */
                0,         /* target: find x so that f(x) = 0 */
                .);        /* Params for f. A missing value indicates param to solve for */
      if status=0 then 
         return( z );      /* root found */
      else return (.);     /* a root was not found */
   endsub;
quit;
 
data Roots1;
input x0 @@;   
root = Root_Func1(x0);     /* x0 is a "guess" for a root of Func1 */
datalines;
-2 0 2
;
 
proc print data=Roots1 noobs; run;

The output shows that the function has found three roots, which are approximately {-2.13, -0.38, 2.33}. These are the same values that I found by using the FROOT function in SAS/IML.

The roots of functions that have parameters

Sometimes it is useful to include parameters in a function. For example, the following function of x contains two parameters, a and b:
    g(x; a, b) = exp(-x2) + a*x3 + b*x +1
Notice that the first function (Func1) is a special case of this function because f(x) = g(x; -1, 5). You can include parameters in the FCMP functions that define the function and that find the roots. When you call the SOLVE function, the last arguments are a list of parameters (x, a, b) and you should give specific values to the a and b parameters and use a missing value to indicate that the x variable is the variable that you want to solve for. This is shown in the following program:

/* you can also define a function that depends on parameters */
proc fcmp outlib=work.funcs.Roots;
   /* define the function. Note Func1(x) = Func2(x; a=-1, b=5) */
   function Func2(x, a, b);
      return( exp(-x**2) + a*x**3 + b*x +1 );
   endsub;
 
   function Root_Func2(x0, a, b);
      array opts[5] init absconv relconv maxiter status; /* initialize missing */
      init = x0;           /* pass in initial guess */
      z = solve("Func2",   /* name of function */
                opts,      /* initial condition, convergence opts, status */
                0,         /* Find x so that f(x) = 0 */
                ., a, b ); /* Params for f. A missing value indicates param to solve for */
      if status=0 then 
         return( z );      /* root found */
      else return (.);     /* a root was not found */
   endsub;
quit;
 
/* Evaluate Func2 for x in [-3,3] for three pairs of (a,b) values:
   (-1,5), (-1,3), and (-2,1) */
data PlotIt;
do x = -3 to 3 by 0.1;
   y = Func2(x, -1, 5); lbl="a=-1; b=5";  output;
   y = Func2(x, -1, 3); lbl="a=-1; b=3";  output;
   y = Func2(x, -2, 1); lbl="a=-2; b=1";  output;
end;
run;
 
title "Graph of User-Defined Functions";
proc sgplot data=PlotIt;
   series x=x y=y / group=lbl;
   refline 0 / axis=y;
   xaxis grid;
   yaxis min=-10 max=10;
run;

The three graphs are shown. You can see that two of the graphs have three roots, but the third graph has only one root. You can call the Root_Func2 function from the DATA step to find the roots for each function:

/* find the roots of Func2 for (a,b) values (-1,5), (-1,3), and (-2,1) */
data Roots2;
input a b x0;
root = Root_Func2(x0, a, b);
datalines;
-1 5 -2 
-1 5  0 
-1 5  2 
-1 3 -2 
-1 3  0 
-1 3  2 
-2 1  0
-2 1  2
;
 
proc print data=Roots2 noobs; run;

Notice that the roots for (a,b) = (-1, 5) are exactly the same as the roots for Func1. The roots for the function when (a,b) = (-1, 3) are approximately {-1.51, -0.64, 1.88}. The root for the function when (a,b) = (-2, 1) is approximately 1.06.

Notice that the initial guess x0 = 0 did not converge to a root for the function that has (a,b) = (-2, 1). It is well known that Newton-type methods do not always converge. This is in contrast to Brent's methods (used by the FROOT function in SAS/IML), which always converges to a root, if one exists.

Summary

In summary, this article shows how to use the SOLVE function in Base SAS to find the roots (zeros) of a nonlinear function of one variable. You first define a nonlinear function by using PROC FCMP. You can call the SOLVE function directly from some SAS procedures. However, if you want to use it in the DATA step, you need to define a second FCMP function that takes the function parameters and an initial guess and calls the SOLVE function. This article shows two examples of using the SOLVE function to find roots in SAS.

The post Find the root of a function by using the SAS DATA step appeared first on The DO Loop.

8月 192020
 

Recently, we announced a strategic partnership between SAS and Microsoft that includes deep integration for SAS technologies across all three of Microsoft’s clouds: Azure, Microsoft 365 and Dynamics 365. As migration of data to the cloud continues to increase, SAS is engineering our software to work in the cloud through [...]

3 types of users who will benefit from the SAS, Microsoft partnership was published on SAS Voices by Tom Fisher

8月 182020
 

As the operations director of any organization’s contact center, you’ll want to ensure that your employees have the right tools in their hands to deliver superior customer service ultimately leading to happy customers and improved revenue for your company. In a previous series on How SAS Visual Analytics’ automated analysis takes customer care to the next level, we saw how automated analysis used machine learning and natural language generation (NLG) to determine which factors were most important in predicting if telecommunications customers would be likely to upgrade to a different mobile plan. We then used this information to create a list of customers our customer care workers could contact to promote our new products. But what about making on-the-fly decisions about what offer(s) best supports a given customer’s needs? To provide support for this type of analysis, SAS recently introduced the automated prediction feature within SAS Visual Analytics on SAS Viya.

What is automated prediction?

Automated prediction, in less than a minute, runs several analytic models (such as decision trees, gradient boosting, and logistic and linear regression) on a specific variable of your choice. Most of the remaining variables in your dataset are automatically analyzed as factors that might influence your specified variable. They are called underlying factors. SAS then chooses the one model (champion model) that most accurately predicts your target variable. The model prediction and the underlying factors are then displayed. You can adjust the values of the underlying factors to determine how the model prediction changes with each adjustment.

Let’s look at how automated prediction works.

Here we have the same customer table we were working within our previous blog posts. This table contains 121 columns (i.e. variables) containing usage and demographic information from a subset of customers who have contacted our customer care centers. One of these columns is a flag that indicates whether that customer upgraded their plan or not. We’ll use this as our target variable.

We’ll right-click on the Upgrade Flag variable and choose Predict on a new page in our report (Figure 1 below).

Figure 1: Selecting automated prediction.

With the automated prediction feature, SAS Visual Analytics created this easy-to-use form in less than a few minutes—by using advanced analytic models and machine learning in the background—that can help predict whether a customer is likely to upgrade (Figure 2 below). SAS analyzed all the other variables in the dataset to determine which ones were most likely to influence our Upgrade Flag. We can modify some of the values in the form and see how it affects the outcome. The factors are listed in order of their relative importance.

Figure 2: Automated Prediction results.

Under the prediction, SAS provides further details using natural language generation (NLG) (Figure 3 below). For example, here we see that the most prevalent value in our data was Did not upgrade with 87.87% of the records having that value. We can also see what type of model was chosen as the champion model; the model that best predicts whether a customer will upgrade. In our current example, the Gradient Boosting model provides the most accurate results.

Figure 3: Natural Language Generation (NLG) provides details about the prediction.

Now, let’s say that a customer calls in. We can fill in the values for each of these parameters listed that are specific to that customer. The analysis is automatically updated using the model previously generated and provides an updated prediction.

Here we see that this customer is likely to upgrade (Figure 4 below). Now we can discuss other mobile plans with this customer.

Figure 4: Updated prediction based on values entered for a specific customer.

What if we want to learn more about the model behind the prediction and what variables were deemed the most important? We can find that information when we maximize the object (Figure 5 below).

Figure 5: Maximize to see model details.

Now we can see at the bottom the steps that were taken to create the champion model (step 2) (Figure 6 below). SAS ran a decision tree, logistic regression, and a gradient boosting model and found that the gradient boosting model provided the greatest accuracy (91.67% accurate in predicting upgrade flag).

Figure 6: Prediction model description.

If we select the Relative Importance tab, we can see the relative importance of each of the underlying factors (Figure 7 below).

Figure 7: Relative importance of underlying factors.

Total Days Over Plan has the greatest influence on our Upgrade Flag variable. Days Suspended Last 6M is the next most important variable whose impact is 43.97% of Total Days Over Plan (Figure 7 above).

Automated Prediction is a fast and easy way to gain an understanding of how variables influence a target and to consider “what if,” by seeing how modifying those underlying factors affects an outcome. Multiple models were run on the data and a champion model was chosen for us using machine learning. We were able to see the accuracy of the champion model and the relative importance of each influencer. All this within a few minutes! This provides a great foundation for moving forward to more advanced modeling techniques. For those who wish to have more control over the models, SAS Visual Analytics also provides capabilities to build and modify other advanced analytical models such as gradient boosting, linear and logistic regression, and decision trees. Furthermore, as your company’s analytic maturing increases additional products can be easily added on to provide even more model choices (Forest, Neural network, Support vector machine, etc.) and capabilities. SAS’ platform and products support the whole analytical life cycle from data preparation all the way through model deployment, model performance management, and decision intelligence.

Take the next step in learning more about SAS Visual Analytics on SAS Viya by signing up for a free trial!

How SAS Visual Analytics' automated prediction takes customer care to the next level was published on SAS Users.

8月 182020
 

As the operations director of any organization’s contact center, you’ll want to ensure that your employees have the right tools in their hands to deliver superior customer service ultimately leading to happy customers and improved revenue for your company. In a previous series on How SAS Visual Analytics’ automated analysis takes customer care to the next level, we saw how automated analysis used machine learning and natural language generation (NLG) to determine which factors were most important in predicting if telecommunications customers would be likely to upgrade to a different mobile plan. We then used this information to create a list of customers our customer care workers could contact to promote our new products. But what about making on-the-fly decisions about what offer(s) best supports a given customer’s needs? To provide support for this type of analysis, SAS recently introduced the automated prediction feature within SAS Visual Analytics on SAS Viya.

What is automated prediction?

Automated prediction, in less than a minute, runs several analytic models (such as decision trees, gradient boosting, and logistic and linear regression) on a specific variable of your choice. Most of the remaining variables in your dataset are automatically analyzed as factors that might influence your specified variable. They are called underlying factors. SAS then chooses the one model (champion model) that most accurately predicts your target variable. The model prediction and the underlying factors are then displayed. You can adjust the values of the underlying factors to determine how the model prediction changes with each adjustment.

Let’s look at how automated prediction works.

Here we have the same customer table we were working within our previous blog posts. This table contains 121 columns (i.e. variables) containing usage and demographic information from a subset of customers who have contacted our customer care centers. One of these columns is a flag that indicates whether that customer upgraded their plan or not. We’ll use this as our target variable.

We’ll right-click on the Upgrade Flag variable and choose Predict on a new page in our report (Figure 1 below).

Figure 1: Selecting automated prediction.

With the automated prediction feature, SAS Visual Analytics created this easy-to-use form in less than a few minutes—by using advanced analytic models and machine learning in the background—that can help predict whether a customer is likely to upgrade (Figure 2 below). SAS analyzed all the other variables in the dataset to determine which ones were most likely to influence our Upgrade Flag. We can modify some of the values in the form and see how it affects the outcome. The factors are listed in order of their relative importance.

Figure 2: Automated Prediction results.

Under the prediction, SAS provides further details using natural language generation (NLG) (Figure 3 below). For example, here we see that the most prevalent value in our data was Did not upgrade with 87.87% of the records having that value. We can also see what type of model was chosen as the champion model; the model that best predicts whether a customer will upgrade. In our current example, the Gradient Boosting model provides the most accurate results.

Figure 3: Natural Language Generation (NLG) provides details about the prediction.

Now, let’s say that a customer calls in. We can fill in the values for each of these parameters listed that are specific to that customer. The analysis is automatically updated using the model previously generated and provides an updated prediction.

Here we see that this customer is likely to upgrade (Figure 4 below). Now we can discuss other mobile plans with this customer.

Figure 4: Updated prediction based on values entered for a specific customer.

What if we want to learn more about the model behind the prediction and what variables were deemed the most important? We can find that information when we maximize the object (Figure 5 below).

Figure 5: Maximize to see model details.

Now we can see at the bottom the steps that were taken to create the champion model (step 2) (Figure 6 below). SAS ran a decision tree, logistic regression, and a gradient boosting model and found that the gradient boosting model provided the greatest accuracy (91.67% accurate in predicting upgrade flag).

Figure 6: Prediction model description.

If we select the Relative Importance tab, we can see the relative importance of each of the underlying factors (Figure 7 below).

Figure 7: Relative importance of underlying factors.

Total Days Over Plan has the greatest influence on our Upgrade Flag variable. Days Suspended Last 6M is the next most important variable whose impact is 43.97% of Total Days Over Plan (Figure 7 above).

Automated Prediction is a fast and easy way to gain an understanding of how variables influence a target and to consider “what if,” by seeing how modifying those underlying factors affects an outcome. Multiple models were run on the data and a champion model was chosen for us using machine learning. We were able to see the accuracy of the champion model and the relative importance of each influencer. All this within a few minutes! This provides a great foundation for moving forward to more advanced modeling techniques. For those who wish to have more control over the models, SAS Visual Analytics also provides capabilities to build and modify other advanced analytical models such as gradient boosting, linear and logistic regression, and decision trees. Furthermore, as your company’s analytic maturing increases additional products can be easily added on to provide even more model choices (Forest, Neural network, Support vector machine, etc.) and capabilities. SAS’ platform and products support the whole analytical life cycle from data preparation all the way through model deployment, model performance management, and decision intelligence.

Take the next step in learning more about SAS Visual Analytics on SAS Viya by signing up for a free trial!

How SAS Visual Analytics' automated prediction takes customer care to the next level was published on SAS Users.

8月 182020
 

As the operations director of any organization’s contact center, you’ll want to ensure that your employees have the right tools in their hands to deliver superior customer service ultimately leading to happy customers and improved revenue for your company. In a previous series on How SAS Visual Analytics’ automated analysis takes customer care to the next level, we saw how automated analysis used machine learning and natural language generation (NLG) to determine which factors were most important in predicting if telecommunications customers would be likely to upgrade to a different mobile plan. We then used this information to create a list of customers our customer care workers could contact to promote our new products. But what about making on-the-fly decisions about what offer(s) best supports a given customer’s needs? To provide support for this type of analysis, SAS recently introduced the automated prediction feature within SAS Visual Analytics on SAS Viya.

What is automated prediction?

Automated prediction, in less than a minute, runs several analytic models (such as decision trees, gradient boosting, and logistic and linear regression) on a specific variable of your choice. Most of the remaining variables in your dataset are automatically analyzed as factors that might influence your specified variable. They are called underlying factors. SAS then chooses the one model (champion model) that most accurately predicts your target variable. The model prediction and the underlying factors are then displayed. You can adjust the values of the underlying factors to determine how the model prediction changes with each adjustment.

Let’s look at how automated prediction works.

Here we have the same customer table we were working within our previous blog posts. This table contains 121 columns (i.e. variables) containing usage and demographic information from a subset of customers who have contacted our customer care centers. One of these columns is a flag that indicates whether that customer upgraded their plan or not. We’ll use this as our target variable.

We’ll right-click on the Upgrade Flag variable and choose Predict on a new page in our report (Figure 1 below).

Figure 1: Selecting automated prediction.

With the automated prediction feature, SAS Visual Analytics created this easy-to-use form in less than a few minutes—by using advanced analytic models and machine learning in the background—that can help predict whether a customer is likely to upgrade (Figure 2 below). SAS analyzed all the other variables in the dataset to determine which ones were most likely to influence our Upgrade Flag. We can modify some of the values in the form and see how it affects the outcome. The factors are listed in order of their relative importance.

Figure 2: Automated Prediction results.

Under the prediction, SAS provides further details using natural language generation (NLG) (Figure 3 below). For example, here we see that the most prevalent value in our data was Did not upgrade with 87.87% of the records having that value. We can also see what type of model was chosen as the champion model; the model that best predicts whether a customer will upgrade. In our current example, the Gradient Boosting model provides the most accurate results.

Figure 3: Natural Language Generation (NLG) provides details about the prediction.

Now, let’s say that a customer calls in. We can fill in the values for each of these parameters listed that are specific to that customer. The analysis is automatically updated using the model previously generated and provides an updated prediction.

Here we see that this customer is likely to upgrade (Figure 4 below). Now we can discuss other mobile plans with this customer.

Figure 4: Updated prediction based on values entered for a specific customer.

What if we want to learn more about the model behind the prediction and what variables were deemed the most important? We can find that information when we maximize the object (Figure 5 below).

Figure 5: Maximize to see model details.

Now we can see at the bottom the steps that were taken to create the champion model (step 2) (Figure 6 below). SAS ran a decision tree, logistic regression, and a gradient boosting model and found that the gradient boosting model provided the greatest accuracy (91.67% accurate in predicting upgrade flag).

Figure 6: Prediction model description.

If we select the Relative Importance tab, we can see the relative importance of each of the underlying factors (Figure 7 below).

Figure 7: Relative importance of underlying factors.

Total Days Over Plan has the greatest influence on our Upgrade Flag variable. Days Suspended Last 6M is the next most important variable whose impact is 43.97% of Total Days Over Plan (Figure 7 above).

Automated Prediction is a fast and easy way to gain an understanding of how variables influence a target and to consider “what if,” by seeing how modifying those underlying factors affects an outcome. Multiple models were run on the data and a champion model was chosen for us using machine learning. We were able to see the accuracy of the champion model and the relative importance of each influencer. All this within a few minutes! This provides a great foundation for moving forward to more advanced modeling techniques. For those who wish to have more control over the models, SAS Visual Analytics also provides capabilities to build and modify other advanced analytical models such as gradient boosting, linear and logistic regression, and decision trees. Furthermore, as your company’s analytic maturing increases additional products can be easily added on to provide even more model choices (Forest, Neural network, Support vector machine, etc.) and capabilities. SAS’ platform and products support the whole analytical life cycle from data preparation all the way through model deployment, model performance management, and decision intelligence.

Take the next step in learning more about SAS Visual Analytics on SAS Viya by signing up for a free trial!

How SAS Visual Analytics' automated prediction takes customer care to the next level was published on SAS Users.