<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Juletip #14 - Export the score code from your VA model and use it in SAS Studio in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-14-Export-the-score-code-from-your-VA-model-and-use-it/m-p/849574#M400</link>
    <description>&lt;P&gt;Have you ever wanted to use a model that you have built in SAS Visual Analytics to score on new unseen data? Well, that is quite simple! Just follow the steps below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: The score code for "SAS Visual Statistics" models will look a little different compared to "SAS Visual Data Mining and Machine Learning" models due to its complexity. I will start by showing you how to do this for a "SAS Visual Statistics" model, before I move over to a "SAS Visual Data Mining and Machine Learning" model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;1&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Lets start by building a simple logistic regression in SAS Visual Analytics.&lt;/P&gt;
&lt;P&gt;The dataset I'm using is for classifying loan default and it is already divided into four datasets. One for each quarter. I will use the dataset for Q1 to train my model, and I will score on Q2 and Q3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll drag and drop the logistic regression object and assign my variables to it. Once it have the necessary variables it will automatically be trained.&lt;/P&gt;
&lt;P&gt;My target variable "BAD" is 1 if the observation had a loan default and 0 if not.&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_30-1670936198011.png" style="width: 1087px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78449i0A5741658FFE4074/image-dimensions/1087x545?v=v2" width="1087" height="545" role="button" title="Lutken_30-1670936198011.png" alt="Lutken_30-1670936198011.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;2.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; Lets say that I'm happy with the model and want to export the model.&lt;/P&gt;
&lt;P&gt;I will click on the three dots in the top right corner of the object and select "Export model...".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_2-1670922697975.png" style="width: 672px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78417i8DF917FCDEC31FB3/image-dimensions/672x425?v=v2" width="672" height="425" role="button" title="Lutken_2-1670922697975.png" alt="Lutken_2-1670922697975.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will then be presented with the score code to your model. You can choose to either copy the score code and paste it into a program in SAS Studio, or you can download it as a .sas file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will show you the latter one. Simply select "Export" as shown below and the score code will be downloaded.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_4-1670923258765.png" style="width: 719px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78420iDC8EFB3B1504FFFC/image-dimensions/719x416?v=v2" width="719" height="416" role="button" title="Lutken_4-1670923258765.png" alt="Lutken_4-1670923258765.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I now have the .sas file in my download folder in the file explorer:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_5-1670923409272.png" style="width: 529px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78421i4F284776B2A9FC2C/image-dimensions/529x102?v=v2" width="529" height="102" role="button" title="Lutken_5-1670923409272.png" alt="Lutken_5-1670923409272.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;3.&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;Next step is to upload this into SAS Studio. Navigate to the folder where you want to upload it and select the upload button.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_28-1670936014559.png" style="width: 806px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78447i8C3BCAB87724207A/image-dimensions/806x504?v=v2" width="806" height="504" role="button" title="Lutken_28-1670936014559.png" alt="Lutken_28-1670936014559.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drag and drop your score code file and select "Upload". You will then see the file in your folder.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_27-1670935870276.png" style="width: 427px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78446i21EBE11BCF9F60B0/image-dimensions/427x391?v=v2" width="427" height="391" role="button" title="Lutken_27-1670935870276.png" alt="Lutken_27-1670935870276.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;4.&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;The score code is now uploaded and ready to use. The code will look something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_29-1670936080481.png" style="width: 1203px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78448i2730FE2A3083978B/image-dimensions/1203x581?v=v2" width="1203" height="581" role="button" title="Lutken_29-1670936080481.png" alt="Lutken_29-1670936080481.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All you have to do, to run this score code on new data, is to wrap it in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the top of the code (line 1) I will add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create cas connection */&lt;BR /&gt;&lt;BR /&gt;cas;
caslib _all_ assign;
&lt;BR /&gt;&lt;BR /&gt;/* The dataset that I will score is called pddata_2_q2 and is located in a library called casuser */&lt;BR /&gt;/* Remember that I trained my model on Q1 and are now scoring on Q2. The result table will be called q2_scored */ &lt;BR /&gt;&lt;BR /&gt;data casuser.q2_scored;
set casuser.pddata_2_q2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will need to close the data step, and I also want to print out some of the results. I will therefore add this to the end of the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* closing the datastep */ &lt;BR /&gt;&lt;BR /&gt;run;
&lt;BR /&gt;&lt;BR /&gt;/* print out 15 observations from the result table */ &lt;BR /&gt;
proc print data=casuser.q2_scored (obs=15);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will print out 15 observations with both the input values and the output values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output values are:&lt;/P&gt;
&lt;P&gt;P_BAD1... = probability of the target variable "BAD" being equal to 1.&lt;/P&gt;
&lt;P&gt;P_BAD0... = probability of the target variable "BAD" being equal to 0.&lt;/P&gt;
&lt;P&gt;I_BAD... = 1 if the&amp;nbsp;P_BAD1 value is above a certain threshold and 0 if not.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_11-1670929290383.png" style="width: 1105px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78430i82676BAB2990A3B4/image-dimensions/1105x433?v=v2" width="1105" height="433" role="button" title="Lutken_11-1670929290383.png" alt="Lutken_11-1670929290383.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The score code for the different "SAS Visual Statistics" models will look very alike. However, the&amp;nbsp;"SAS Visual Data Mining and Machine Learning" models are more complex and the score code will look different.&lt;/P&gt;
&lt;P&gt;Lets try to build a gradient boosting model by following the same steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;1&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Lets start by duplicating our current model into a gradient boosting model like this: (since we are duplicating the model, it will use the same variables)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_25-1670935617685.png" style="width: 1100px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78444iF61D47037D3BEC8B/image-dimensions/1100x553?v=v2" width="1100" height="553" role="button" title="Lutken_25-1670935617685.png" alt="Lutken_25-1670935617685.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;2&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Exporting the score code is done the same way, but with an additional step:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_22-1670935332033.png" style="width: 1105px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78441i05BED5A3684EBD87/image-dimensions/1105x493?v=v2" width="1105" height="493" role="button" title="Lutken_22-1670935332033.png" alt="Lutken_22-1670935332033.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When selecting "Export model..." you will be told to create a table name for a table that will be saved in cas. This table will be called upon in the score code. Press "OK".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_14-1670933255628.png" style="width: 763px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78433i1C22869C007BD531/image-dimensions/763x413?v=v2" width="763" height="413" role="button" title="Lutken_14-1670933255628.png" alt="Lutken_14-1670933255628.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will then be presented with the score code. This can either be copied and pasted into a program in SAS Studio or downloaded as a .sas file.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_15-1670933504391.png" style="width: 1017px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78434i4820AEBB2563BD2B/image-dimensions/1017x701?v=v2" width="1017" height="701" role="button" title="Lutken_15-1670933504391.png" alt="Lutken_15-1670933504391.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;3&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;After I selected "Export" and opened SAS Studio, I can upload the file in my folder:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_20-1670935043327.png" style="width: 1084px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78439i994F15B6EAE1D669/image-dimensions/1084x675?v=v2" width="1084" height="675" role="button" title="Lutken_20-1670935043327.png" alt="Lutken_20-1670935043327.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;4&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Once it is uploaded I can open it and do the necessary changes in order to use it to score on new data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The score code will look something like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_18-1670934057853.png" style="width: 1035px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78437i95F20BC8F86070EE/image-dimensions/1035x704?v=v2" width="1035" height="704" role="button" title="Lutken_18-1670934057853.png" alt="Lutken_18-1670934057853.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All you need to change are the macro variables that are in the orange square. These macro variables are used as input throughout the code.&lt;/P&gt;
&lt;P&gt;Once the changes are done you can run the code to score the new dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end of the code you can also add this procedure to print out some scored observations. Here I am also using the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Print out sample of the results */ &lt;BR /&gt;
proc print data=&amp;amp;DEST_LIB..&amp;amp;DEST_DATA (obs=15);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output will look the same as for the previous score code, with both the input values and the predicted values. It will also present a table with information of where the results are saved, and how many rows and columns:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_19-1670934617580.png" style="width: 1084px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78438i8959E1E49280E429/image-dimensions/1084x512?v=v2" width="1084" height="512" role="button" title="Lutken_19-1670934617580.png" alt="Lutken_19-1670934617580.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2022 08:15:12 GMT</pubDate>
    <dc:creator>Lutken</dc:creator>
    <dc:date>2022-12-14T08:15:12Z</dc:date>
    <item>
      <title>Juletip #14 - Export the score code from your VA model and use it in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-14-Export-the-score-code-from-your-VA-model-and-use-it/m-p/849574#M400</link>
      <description>&lt;P&gt;Have you ever wanted to use a model that you have built in SAS Visual Analytics to score on new unseen data? Well, that is quite simple! Just follow the steps below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: The score code for "SAS Visual Statistics" models will look a little different compared to "SAS Visual Data Mining and Machine Learning" models due to its complexity. I will start by showing you how to do this for a "SAS Visual Statistics" model, before I move over to a "SAS Visual Data Mining and Machine Learning" model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;1&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Lets start by building a simple logistic regression in SAS Visual Analytics.&lt;/P&gt;
&lt;P&gt;The dataset I'm using is for classifying loan default and it is already divided into four datasets. One for each quarter. I will use the dataset for Q1 to train my model, and I will score on Q2 and Q3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll drag and drop the logistic regression object and assign my variables to it. Once it have the necessary variables it will automatically be trained.&lt;/P&gt;
&lt;P&gt;My target variable "BAD" is 1 if the observation had a loan default and 0 if not.&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_30-1670936198011.png" style="width: 1087px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78449i0A5741658FFE4074/image-dimensions/1087x545?v=v2" width="1087" height="545" role="button" title="Lutken_30-1670936198011.png" alt="Lutken_30-1670936198011.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;2.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; Lets say that I'm happy with the model and want to export the model.&lt;/P&gt;
&lt;P&gt;I will click on the three dots in the top right corner of the object and select "Export model...".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_2-1670922697975.png" style="width: 672px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78417i8DF917FCDEC31FB3/image-dimensions/672x425?v=v2" width="672" height="425" role="button" title="Lutken_2-1670922697975.png" alt="Lutken_2-1670922697975.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will then be presented with the score code to your model. You can choose to either copy the score code and paste it into a program in SAS Studio, or you can download it as a .sas file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will show you the latter one. Simply select "Export" as shown below and the score code will be downloaded.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_4-1670923258765.png" style="width: 719px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78420iDC8EFB3B1504FFFC/image-dimensions/719x416?v=v2" width="719" height="416" role="button" title="Lutken_4-1670923258765.png" alt="Lutken_4-1670923258765.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I now have the .sas file in my download folder in the file explorer:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_5-1670923409272.png" style="width: 529px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78421i4F284776B2A9FC2C/image-dimensions/529x102?v=v2" width="529" height="102" role="button" title="Lutken_5-1670923409272.png" alt="Lutken_5-1670923409272.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;3.&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;Next step is to upload this into SAS Studio. Navigate to the folder where you want to upload it and select the upload button.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_28-1670936014559.png" style="width: 806px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78447i8C3BCAB87724207A/image-dimensions/806x504?v=v2" width="806" height="504" role="button" title="Lutken_28-1670936014559.png" alt="Lutken_28-1670936014559.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drag and drop your score code file and select "Upload". You will then see the file in your folder.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_27-1670935870276.png" style="width: 427px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78446i21EBE11BCF9F60B0/image-dimensions/427x391?v=v2" width="427" height="391" role="button" title="Lutken_27-1670935870276.png" alt="Lutken_27-1670935870276.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;4.&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;The score code is now uploaded and ready to use. The code will look something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_29-1670936080481.png" style="width: 1203px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78448i2730FE2A3083978B/image-dimensions/1203x581?v=v2" width="1203" height="581" role="button" title="Lutken_29-1670936080481.png" alt="Lutken_29-1670936080481.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All you have to do, to run this score code on new data, is to wrap it in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the top of the code (line 1) I will add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create cas connection */&lt;BR /&gt;&lt;BR /&gt;cas;
caslib _all_ assign;
&lt;BR /&gt;&lt;BR /&gt;/* The dataset that I will score is called pddata_2_q2 and is located in a library called casuser */&lt;BR /&gt;/* Remember that I trained my model on Q1 and are now scoring on Q2. The result table will be called q2_scored */ &lt;BR /&gt;&lt;BR /&gt;data casuser.q2_scored;
set casuser.pddata_2_q2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will need to close the data step, and I also want to print out some of the results. I will therefore add this to the end of the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* closing the datastep */ &lt;BR /&gt;&lt;BR /&gt;run;
&lt;BR /&gt;&lt;BR /&gt;/* print out 15 observations from the result table */ &lt;BR /&gt;
proc print data=casuser.q2_scored (obs=15);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will print out 15 observations with both the input values and the output values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output values are:&lt;/P&gt;
&lt;P&gt;P_BAD1... = probability of the target variable "BAD" being equal to 1.&lt;/P&gt;
&lt;P&gt;P_BAD0... = probability of the target variable "BAD" being equal to 0.&lt;/P&gt;
&lt;P&gt;I_BAD... = 1 if the&amp;nbsp;P_BAD1 value is above a certain threshold and 0 if not.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_11-1670929290383.png" style="width: 1105px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78430i82676BAB2990A3B4/image-dimensions/1105x433?v=v2" width="1105" height="433" role="button" title="Lutken_11-1670929290383.png" alt="Lutken_11-1670929290383.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The score code for the different "SAS Visual Statistics" models will look very alike. However, the&amp;nbsp;"SAS Visual Data Mining and Machine Learning" models are more complex and the score code will look different.&lt;/P&gt;
&lt;P&gt;Lets try to build a gradient boosting model by following the same steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;1&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Lets start by duplicating our current model into a gradient boosting model like this: (since we are duplicating the model, it will use the same variables)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_25-1670935617685.png" style="width: 1100px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78444iF61D47037D3BEC8B/image-dimensions/1100x553?v=v2" width="1100" height="553" role="button" title="Lutken_25-1670935617685.png" alt="Lutken_25-1670935617685.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;2&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Exporting the score code is done the same way, but with an additional step:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_22-1670935332033.png" style="width: 1105px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78441i05BED5A3684EBD87/image-dimensions/1105x493?v=v2" width="1105" height="493" role="button" title="Lutken_22-1670935332033.png" alt="Lutken_22-1670935332033.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When selecting "Export model..." you will be told to create a table name for a table that will be saved in cas. This table will be called upon in the score code. Press "OK".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_14-1670933255628.png" style="width: 763px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78433i1C22869C007BD531/image-dimensions/763x413?v=v2" width="763" height="413" role="button" title="Lutken_14-1670933255628.png" alt="Lutken_14-1670933255628.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will then be presented with the score code. This can either be copied and pasted into a program in SAS Studio or downloaded as a .sas file.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_15-1670933504391.png" style="width: 1017px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78434i4820AEBB2563BD2B/image-dimensions/1017x701?v=v2" width="1017" height="701" role="button" title="Lutken_15-1670933504391.png" alt="Lutken_15-1670933504391.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;3&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;After I selected "Export" and opened SAS Studio, I can upload the file in my folder:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_20-1670935043327.png" style="width: 1084px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78439i994F15B6EAE1D669/image-dimensions/1084x675?v=v2" width="1084" height="675" role="button" title="Lutken_20-1670935043327.png" alt="Lutken_20-1670935043327.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;&lt;FONT size="4"&gt;4&lt;/FONT&gt;.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;Once it is uploaded I can open it and do the necessary changes in order to use it to score on new data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The score code will look something like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_18-1670934057853.png" style="width: 1035px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78437i95F20BC8F86070EE/image-dimensions/1035x704?v=v2" width="1035" height="704" role="button" title="Lutken_18-1670934057853.png" alt="Lutken_18-1670934057853.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All you need to change are the macro variables that are in the orange square. These macro variables are used as input throughout the code.&lt;/P&gt;
&lt;P&gt;Once the changes are done you can run the code to score the new dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end of the code you can also add this procedure to print out some scored observations. Here I am also using the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Print out sample of the results */ &lt;BR /&gt;
proc print data=&amp;amp;DEST_LIB..&amp;amp;DEST_DATA (obs=15);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output will look the same as for the previous score code, with both the input values and the predicted values. It will also present a table with information of where the results are saved, and how many rows and columns:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lutken_19-1670934617580.png" style="width: 1084px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78438i8959E1E49280E429/image-dimensions/1084x512?v=v2" width="1084" height="512" role="button" title="Lutken_19-1670934617580.png" alt="Lutken_19-1670934617580.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 08:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-14-Export-the-score-code-from-your-VA-model-and-use-it/m-p/849574#M400</guid>
      <dc:creator>Lutken</dc:creator>
      <dc:date>2022-12-14T08:15:12Z</dc:date>
    </item>
  </channel>
</rss>

