<?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 distinct column from excel IF function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423465#M104150</link>
    <description>&lt;P&gt;If you have access to an Excel formula as a text string then you could use pattern matching to extract variable names. Start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
if not prxId then prxId + prxParse("/[[:alpha:]]\w*/o");
str = "DED_LAYER_BENCHMARK_LP = =if(_DataCell_ULFBL&amp;lt;=_InputCell_Deductible,
_DataCell_Original_Bench_LP_r0000_c0000,0) + if(_DataCell_ULFBL + 
_InputCell_Layer_r0000_c0000 &amp;lt;= _InputCell_Deductible, 
_DataCell_Original_Bench_LP_r0001_c0000, 0)";

start = 1;
stop = length(str);
call prxnext(prxId ,start, stop, str, pos, len);
do while (pos &amp;gt; 0);
    var = substr(str, pos, len);
    output;
    call prxnext(prxId, start, stop, str, pos, len);
    end;
keep var;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Dec 2017 21:14:34 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-12-23T21:14:34Z</dc:date>
    <item>
      <title>Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423454#M104142</link>
      <description>&lt;P&gt;DED_LAYER_BENCHMARK_LP = =if(_DataCell_ULFBL&amp;lt;=_InputCell_Deductible,&lt;/P&gt;&lt;P&gt;_DataCell_Original_Bench_LP_r0000_c0000,0) + if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 &amp;lt;= _InputCell_Deductible, _DataCell_Original_Bench_LP_r0001_c0000, 0)&lt;/P&gt;&lt;P&gt;I want to create a new column which will have all distinct column used inside Excel IF function:&lt;BR /&gt;&amp;nbsp; _DataCell_ULFBL&lt;/P&gt;&lt;P&gt;_InputCell_Deductible&lt;/P&gt;&lt;P&gt;_DataCell_Original_Bench_LP_r0000_c0000&lt;/P&gt;&lt;P&gt;_DataCell_Original_Bench_LP_r0001_c0000&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2017 18:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423454#M104142</guid>
      <dc:creator>subrat1</dc:creator>
      <dc:date>2017-12-23T18:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423455#M104143</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt; It's not clear to me what you want. If you already have an Excel sheet with a formula, SAS will NOT read or execute the formula.&lt;BR /&gt;&lt;BR /&gt; If you want to create a new column in a SAS dataset based on another column in the dataset, then that is possible. Something like this:&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data new;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt; set sashelp.class;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt; newage = age + 5;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt; if sex = 'F' then newht = height+.5;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt; else if sex = 'M' then newht = height+.75;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;In this DATA step program, every student in SASHELP.CLASS will have a new column created called NEWAGE by adding 5 to the AGE value in the data.&lt;BR /&gt;&lt;BR /&gt;Then, every student will have a column called NEWHT that is assigned a value based on the value of the SEX variable. &lt;BR /&gt;&lt;BR /&gt;Hope that helps,&lt;BR /&gt;&lt;BR /&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2017 19:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423455#M104143</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-12-23T19:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423456#M104144</link>
      <description>I just wanted to separate columns name inside IF function</description>
      <pubDate>Sat, 23 Dec 2017 19:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423456#M104144</guid>
      <dc:creator>subrat1</dc:creator>
      <dc:date>2017-12-23T19:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423459#M104146</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/90394"&gt;@subrat1&lt;/a&gt; wrote:&lt;BR /&gt;I just wanted to separate columns name inside IF function&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is absolutely not clear what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of posting Excel, perhaps consider posting raw data and what you expect as output.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2017 19:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423459#M104146</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-23T19:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423463#M104149</link>
      <description>&lt;P&gt;Not sure what Excel has to do with the problem.&amp;nbsp; If you have a string that looks like this:&lt;/P&gt;
&lt;PRE&gt;if(_DataCell_ULFBL&amp;lt;=_InputCell_Deductible
  ,_DataCell_Original_Bench_LP_r0000_c0000
  ,0
)
 + 
if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 &amp;lt;= _InputCell_Deductible
  , _DataCell_Original_Bench_LP_r0001_c0000
  , 0
)
&lt;/PRE&gt;
&lt;P&gt;And you want to scan it to find distinct words then COUNTW() and SCAN() are useful.&lt;/P&gt;
&lt;P&gt;Let's make some test data from your example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  str = '
if(_DataCell_ULFBL&amp;lt;=_InputCell_Deductible
  ,_DataCell_Original_Bench_LP_r0000_c0000
  ,0
)
 + 
if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 &amp;lt;= _InputCell_Deductible
  , _DataCell_Original_Bench_LP_r0001_c0000
  , 0
)
' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's parse it into words.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data words ;
  set have ;
  length word $100 ;
  do i=1 to countw(str,'(, +-*/&amp;lt;=&amp;gt;)');
    word=upcase(scan(str,i,'(, +-*/)&amp;lt;=&amp;gt;'));
    output;
  end;
run;
proc sort nodupkey ;
  by word;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will probably want to figure out how to eliminate the function names and numeric constants.&amp;nbsp; And also the names that are longer than 32 characters and so invalid as SAS variable names.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 394px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17521iF5599C23826A10FF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2017 21:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423463#M104149</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-23T21:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create distinct column from excel IF function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423465#M104150</link>
      <description>&lt;P&gt;If you have access to an Excel formula as a text string then you could use pattern matching to extract variable names. Start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
if not prxId then prxId + prxParse("/[[:alpha:]]\w*/o");
str = "DED_LAYER_BENCHMARK_LP = =if(_DataCell_ULFBL&amp;lt;=_InputCell_Deductible,
_DataCell_Original_Bench_LP_r0000_c0000,0) + if(_DataCell_ULFBL + 
_InputCell_Layer_r0000_c0000 &amp;lt;= _InputCell_Deductible, 
_DataCell_Original_Bench_LP_r0001_c0000, 0)";

start = 1;
stop = length(str);
call prxnext(prxId ,start, stop, str, pos, len);
do while (pos &amp;gt; 0);
    var = substr(str, pos, len);
    output;
    call prxnext(prxId, start, stop, str, pos, len);
    end;
keep var;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Dec 2017 21:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-distinct-column-from-excel-IF-function/m-p/423465#M104150</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-12-23T21:14:34Z</dc:date>
    </item>
  </channel>
</rss>

