DED_LAYER_BENCHMARK_LP = =if(_DataCell_ULFBL<=_InputCell_Deductible,
_DataCell_Original_Bench_LP_r0000_c0000,0) + if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 <= _InputCell_Deductible, _DataCell_Original_Bench_LP_r0001_c0000, 0)
I want to create a new column which will have all distinct column used inside Excel IF function:
_DataCell_ULFBL
_InputCell_Deductible
_DataCell_Original_Bench_LP_r0000_c0000
_DataCell_Original_Bench_LP_r0001_c0000
Hi:
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.
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:
data new;
set sashelp.class;
newage = age + 5;
if sex = 'F' then newht = height+.5;
else if sex = 'M' then newht = height+.75;
run;
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.
Then, every student will have a column called NEWHT that is assigned a value based on the value of the SEX variable.
Hope that helps,
cynthia
@subrat1 wrote:
I just wanted to separate columns name inside IF function
It is absolutely not clear what you want.
Instead of posting Excel, perhaps consider posting raw data and what you expect as output.
Not sure what Excel has to do with the problem. If you have a string that looks like this:
if(_DataCell_ULFBL<=_InputCell_Deductible ,_DataCell_Original_Bench_LP_r0000_c0000 ,0 ) + if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 <= _InputCell_Deductible , _DataCell_Original_Bench_LP_r0001_c0000 , 0 )
And you want to scan it to find distinct words then COUNTW() and SCAN() are useful.
Let's make some test data from your example.
data have ;
str = '
if(_DataCell_ULFBL<=_InputCell_Deductible
,_DataCell_Original_Bench_LP_r0000_c0000
,0
)
+
if(_DataCell_ULFBL + _InputCell_Layer_r0000_c0000 <= _InputCell_Deductible
, _DataCell_Original_Bench_LP_r0001_c0000
, 0
)
' ;
run;
Now let's parse it into words.
data words ;
set have ;
length word $100 ;
do i=1 to countw(str,'(, +-*/<=>)');
word=upcase(scan(str,i,'(, +-*/)<=>'));
output;
end;
run;
proc sort nodupkey ;
by word;
run;
You will probably want to figure out how to eliminate the function names and numeric constants. And also the names that are longer than 32 characters and so invalid as SAS variable names.
If you have access to an Excel formula as a text string then you could use pattern matching to extract variable names. Start with:
data test;
if not prxId then prxId + prxParse("/[[:alpha:]]\w*/o");
str = "DED_LAYER_BENCHMARK_LP = =if(_DataCell_ULFBL<=_InputCell_Deductible,
_DataCell_Original_Bench_LP_r0000_c0000,0) + if(_DataCell_ULFBL +
_InputCell_Layer_r0000_c0000 <= _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 > 0);
var = substr(str, pos, len);
output;
call prxnext(prxId, start, stop, str, pos, len);
end;
keep var;
run;
proc print; run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.