<?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 Re: Create new variable based on another column in SAS Visual Analytics</title>
    <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966118#M18759</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if it was possible to create the wanted table using the sas visual analytics functions such as calculated item, aggregate meassures or similar. Do you know if that is possible?&lt;/P&gt;</description>
    <pubDate>Fri, 09 May 2025 06:22:15 GMT</pubDate>
    <dc:creator>Jan_Jensen</dc:creator>
    <dc:date>2025-05-09T06:22:15Z</dc:date>
    <item>
      <title>Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966050#M18757</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a new variable based on another column in sas visual analytics. I have this dataformat:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ItemID&lt;/TD&gt;&lt;TD&gt;ItemID_reference&lt;/TD&gt;&lt;TD&gt;My wanted output&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1111&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2222&lt;/TD&gt;&lt;TD&gt;8888&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3333&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4444&lt;/TD&gt;&lt;TD&gt;1111&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5555&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6666&lt;/TD&gt;&lt;TD&gt;7777&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7777&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I match the value from ItemID_reference to the values of ItemID? In other words: If a value of ItemID_reference is any of ItemID, return 1 else 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 07:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966050#M18757</guid>
      <dc:creator>Jan_Jensen</dc:creator>
      <dc:date>2025-05-08T07:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966059#M18758</link>
      <description>&lt;P&gt;Create a lookup table of IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input (ItemID ItemID_reference)(:$8.);
   cards;
1111  .  
2222  8888  
3333  .  
4444  1111  
5555  .  
6666  7777
7777  .
;;;;
   run;
proc print;
   run;

proc sort nodupkey 
      data=have(keep=ItemID rename=(ItemID=ItemID_reference))
      out=ref(index=(ItemID_reference/unique))
      ;
   by ItemID_reference;
   run;
proc print;
   run;

data want;
   set have;
   set ref key=ItemID_reference/unique;
   if _iorc_ eq 0 then flag=1;
   else do;
      flag=0;
      _error_=0;
      end;
   run;
proc print; 
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 221px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106803i1467EEA846AEB98C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 12:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966059#M18758</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-05-08T12:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966118#M18759</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if it was possible to create the wanted table using the sas visual analytics functions such as calculated item, aggregate meassures or similar. Do you know if that is possible?&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 06:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966118#M18759</guid>
      <dc:creator>Jan_Jensen</dc:creator>
      <dc:date>2025-05-09T06:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966165#M18760</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475173"&gt;@Jan_Jensen&lt;/a&gt;&amp;nbsp;sorry I did not notice that you posted this for Visual Analytics.&amp;nbsp; I do not know or use VA and cannot help.&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 15:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966165#M18760</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-05-09T15:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966173#M18761</link>
      <description>&lt;P&gt;I haven't fully thought this through yet and am not 100% certain I would fully endorse this process, but I was able to get something working here:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HunterT_SAS_0-1746805301021.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106843i95A82CEEA6AFD593/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HunterT_SAS_0-1746805301021.png" alt="HunterT_SAS_0-1746805301021.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Overall this is not something Visual Analytics can easily do. The way I was able to get it to work is a bit complicated and involves a couple of aggregated datasources and joined datasources so if your tables are very large, I would not advise doing this in a real report.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The process though is this. I'm going to call your original datasource "Original".&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;1. Create an aggregated datasource with just the "ItemID" column&lt;BR /&gt;2. Create a second aggregated datasource with just the "ItemID_reference" column&lt;BR /&gt;3. Join the two aggregated tables together using an INNER join and matching the two ID columns. The end result should be a table that only has matches (2 rows in this example, one for 1111 and one for 7777).&lt;/P&gt;
&lt;P&gt;4. Join Original and the new join back together using a LEFT join on Original. Map the ItemID_reference columns from each. I included all columns, and you should end up with something like this, and I've renamed each column to make it clear where they came from:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HunterT_SAS_1-1746805772604.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106844iECFE0A2AA9E07CAB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HunterT_SAS_1-1746805772604.png" alt="HunterT_SAS_1-1746805772604.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;5. Create a calculated item like this:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;'ItemID_reference (original)'n&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;'ItemID_reference (1st join)'n&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;AND&lt;/SPAN&gt; &lt;SPAN&gt;NotMissing&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'ItemID_reference (1st join)'n&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;ELSE&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Outside of something like that, I don't see how this can be done in Visual Analytics. The major downside to creating Aggregated Datasources and Joins like this is that the tables get created at runtime in the user's personal CAS library so if your real table are large, you have some risk of performance issues and using up space in CAS.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The better answer might be to handle this calculation outside of Visual Analytics before loading the data into CAS.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 15:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/966173#M18761</guid>
      <dc:creator>HunterT_SAS</dc:creator>
      <dc:date>2025-05-09T15:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on another column</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/967119#M18784</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475173"&gt;@Jan_Jensen&lt;/a&gt;&amp;nbsp;, does this answer your question? The code and result are as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data itemfl1;
   input itemid itemid_ref;
   datalines;
1111 .
2222 8888
3333 .
4444 1111
5555 .
6666 7777
7777 .
;
run;
proc sql noprint;
select distinct itemid
   into :itemidlist separated by ','
   from itemfl1;
quit;
data itemfl2;
   set itemfl1;
   if itemid_ref in (&amp;amp;itemidlist)
      then flag=1;
      else flag=0;
run;
proc print data=itemfl2;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1747839964384.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107196i95EA4A88132EE396/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1747839964384.png" alt="dxiao2017_0-1747839964384.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 15:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Create-new-variable-based-on-another-column/m-p/967119#M18784</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-21T15:07:04Z</dc:date>
    </item>
  </channel>
</rss>

