<?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: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793286#M254235</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385687"&gt;@seohyeonjeong&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I've understood your requirements, the following code might help. It merges the data with itself, with one of the inputs offset to the next record:&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;/* set up input data */
data have;
	input contractno $char5.;

	datalines;
ZA3LE
ZA3LE
ZC2G3
ZV3GS
ZV3GS
ZV3GS
;


/* merge data with itself, starting one input from the 2nd obs */
data want(drop = next_contractno);
	merge have(firstobs = 2 rename = contractno = next_contractno)
		  have;
		  
	/* true gives 1, false give 0 */
	dupcheck = contractno ne next_contractno;
run;


/* display results */
proc print data = want;
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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Improved comment.&lt;/P&gt;</description>
    <pubDate>Sun, 30 Jan 2022 11:31:52 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2022-01-30T11:31:52Z</dc:date>
    <item>
      <title>How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793253#M254224</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to make a new column named DupCheck which compares right below row and set a flag.&lt;/P&gt;&lt;P&gt;Excel function: =IF(B1=B2, 0, 1) is used for putting the flag of the duplication.&lt;/P&gt;&lt;P&gt;The table is ordered by contractNo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rowN ContractNo&amp;nbsp; &amp;nbsp; DupCheck&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA3LE　　　0&lt;/P&gt;&lt;P&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA3LE　　　1&lt;/P&gt;&lt;P&gt;&amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZC2G3　　&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a function below but it has a big problem when it comes to having more than two same variables and the wrong first row flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT 
g1.*
,case when g1.contractNo =g2.contractNo then 0 else 1 end as dupCheck
FROM table g1
INNER JOIN table g2
ON g1.rowN = g1.rowN-1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will appreciate your help!&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 04:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793253#M254224</guid>
      <dc:creator>seohyeonjeong</dc:creator>
      <dc:date>2022-01-29T04:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793262#M254227</link>
      <description>SELECT &lt;BR /&gt;g1.*&lt;BR /&gt;, ifn( g1.contractNo =g2.contractNo , 0 ,1 ) as dupCheck&lt;BR /&gt;FROM table g1&lt;BR /&gt;</description>
      <pubDate>Sat, 29 Jan 2022 05:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793262#M254227</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-29T05:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793286#M254235</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385687"&gt;@seohyeonjeong&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I've understood your requirements, the following code might help. It merges the data with itself, with one of the inputs offset to the next record:&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;/* set up input data */
data have;
	input contractno $char5.;

	datalines;
ZA3LE
ZA3LE
ZC2G3
ZV3GS
ZV3GS
ZV3GS
;


/* merge data with itself, starting one input from the 2nd obs */
data want(drop = next_contractno);
	merge have(firstobs = 2 rename = contractno = next_contractno)
		  have;
		  
	/* true gives 1, false give 0 */
	dupcheck = contractno ne next_contractno;
run;


/* display results */
proc print data = want;
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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Improved comment.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 11:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793286#M254235</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-01-30T11:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793287#M254236</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt;&amp;nbsp;provides a good answer for your case, where you need to compare a value from one record with that of the next record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS functions IFN and IFC offer the equivalent feature to the Excel IF function. But if your goal is a binary flag only (0 or 1), then you can rely on the fact that a condition in SQL will result in a 1 or 0 output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc sql;
 select (age&amp;gt;=13) as isTeen 
  from sashelp.class;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result&amp;nbsp;&lt;STRONG&gt;isTeen&lt;/STRONG&gt; column will have a 1 if the subject is 13 or older, 0 if not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a SAS function like IFN or IFC is valid in PROC SQL but it may not pass to the underlying database if your data source is in something like Oracle or SQL Server -- and that can result in more data movement behind the scenes. For more complex condition checking or non-binary flags, I recommend using the CASE-WHEN-THEN-ELSE structure, which is standard in SQL. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc sql;
 select 
 case 
  when (age &amp;lt;=13) then 'Young'
  when (age between 14 and 15) then 'Mid'
  else 'Old' 
  end as ageRange
  from sashelp.class;
quit;&lt;/LI-CODE&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;</description>
      <pubDate>Sat, 29 Jan 2022 13:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793287#M254236</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2022-01-29T13:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793288#M254237</link>
      <description>Thank you, Amir.&lt;BR /&gt;&lt;BR /&gt;This will help me in the future, but I'm finding a way in proc sql.&lt;BR /&gt;My manager asked me to make it work in proc sql.&lt;BR /&gt;&lt;BR /&gt;But thank you so much!</description>
      <pubDate>Sat, 29 Jan 2022 14:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793288#M254237</guid>
      <dc:creator>seohyeonjeong</dc:creator>
      <dc:date>2022-01-29T14:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793294#M254240</link>
      <description>&lt;P&gt;This will be much easier if you process the data the way normal SAS works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result of a boolean expression is already going to be code 0/1 so no need for the IF() function (called IFN() or IFC() in SAS or CASE expression in SQL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL does not have any concept of ordered data.&amp;nbsp; That is why you had to introduce the ROWN variable.&amp;nbsp; But using a DATA step the records are processed sequentially.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is much easier to remember something from the past than it is to predict the future.&amp;nbsp; So use the LAG() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  rowN+1;
  input ContractNo :$10. @@ ;
cards;
ZA3LE ZA3LE ZC2G3 ZV3GS ZV3GS ZV3GS
;

data want ;
  set have;
  dup = contractno=lag(contractno);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really need to have the flag on the first duplicate instead of the second duplicate then use your ROWN variable to re-order the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=descending;
  by descending rown;
run;

data want2;
  set descending;
  by descending rown;
  dup_check = contractno=lag(contractno);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;               Contract     dup_
Obs    rowN       No       check

 1       6      ZV3GS        0
 2       5      ZV3GS        1
 3       4      ZV3GS        1
 4       3      ZC2G3        0
 5       2      ZA3LE        0
 6       1      ZA3LE        1

&lt;/PRE&gt;
&lt;P&gt;But I am not sure how useful either flag is going to be.&amp;nbsp; If you want to check for values of CONTRACTNO that repeat (form a run of the same value) then use BY group processing.&amp;nbsp; Then you can flag ALL of the observations in the duplicate run.&amp;nbsp; Of locate the FIRST one or the LAST one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want3;
  set have;
  by contractno notsorted;
  dup = not (first.contractno and last.contractno);
  first=first.contractno;
  last=last.contractno;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;               Contract
Obs    rowN       No       dup    first    last

 1       1      ZA3LE       1       1        0
 2       2      ZA3LE       1       0        1
 3       3      ZC2G3       0       1        1
 4       4      ZV3GS       1       1        0
 5       5      ZV3GS       1       0        0
 6       6      ZV3GS       1       0        1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 17:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793294#M254240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-29T17:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793309#M254250</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385687"&gt;@seohyeonjeong&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no choice, except to use sql, then the below code shows a possible solution, but there is a lot more preparation work involved. This is why the data step is a more straightforward approach, so it might be worth finding out why you are being asked to use sql instead of a data step, perhaps there is a good reason but it does not appear to be obvious to any of us at the moment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set up input data */
data have;
	input contractno $char5.;

	datalines;
ZA3LE
ZA3LE
ZC2G3
ZV3GS
ZV3GS
ZV3GS
;


/* generate two input data sets with sequence numbers */
data have1 have2;
	set have;
	
	/* only output to have2 from the 2nd observation */
	if seq then
		output have2;
		
	seq + 1;
		
	output have1;
run;


/* use sql to left join on seq */
proc sql;
	create table
		want
	as
	select
		 have1.contractno
		,have1.contractno ne have2.contractno as dupcheck
	from
		have1
	left join
		have2
	on
		have1.seq eq have2.seq
	;
quit;


/* display results */
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 20:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793309#M254250</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-01-29T20:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793331#M254257</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385687"&gt;@seohyeonjeong&lt;/a&gt;&amp;nbsp;Especially given your data is already sorted by contractno using sequential SAS data step by group processing is so much more efficient than SQL in your case - both from a coding and processing perspective.&lt;/P&gt;
&lt;P&gt;If your source data resides in a database then using SQL might be the right thing to do - but else there is really no reason for using SQL here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare all the code and processing required to create want_1 as compared to the little it takes to create want_2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set up input data */
data have;
	input contractno $char5.;
	datalines;
ZA3LE
ZA3LE
ZC2G3
ZV3GS
ZV3GS
ZV3GS
;

data inter;
  set have;
  row_id=_n_;
run;

proc sql;
  create table want_1 as
  select 
    o.contractno,
    case
      when not missing(i.row_id) then 1
      else 0
      end as dupcheck
  from 
    inter o
    left join
    (
      select
        contractno,
        max(row_id) as row_id
      from inter
      group by contractno
    ) i
    on o.contractno=i.contractno
      and o.row_id=i.row_id
    order by o.row_id
  ;
quit;

data want_2;
  set have;
  by contractno;
  dupcheck= last.contractno;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Jan 2022 02:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793331#M254257</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-30T02:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793359#M254276</link>
      <description>&lt;P&gt;Why is Row 5 not a duplicate of Row 4 in your example? Is that a typo or do you actually mean something other than the Excel example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385687"&gt;@seohyeonjeong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to make a new column named DupCheck which compares right below row and set a flag.&lt;/P&gt;
&lt;P&gt;Excel function: =IF(B1=B2, 0, 1) is used for putting the flag of the duplication.&lt;/P&gt;
&lt;P&gt;The table is ordered by contractNo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rowN ContractNo&amp;nbsp; &amp;nbsp; DupCheck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA3LE　　　0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA3LE　　　1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZC2G3　　&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZV3GS　　&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made a function below but it has a big problem when it comes to having more than two same variables and the wrong first row flag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SELECT 
g1.*
,case when g1.contractNo =g2.contractNo then 0 else 1 end as dupCheck
FROM table g1
INNER JOIN table g2
ON g1.rowN = g1.rowN-1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will appreciate your help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 12:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793359#M254276</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-30T12:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793930#M254525</link>
      <description>Our dept uses SAS Enterprise Guide which is the only way to access DB now, but we are planning to change our work environment on AWS (Athena). That's the reason I have to make the code in proc SQL as possible I can.&lt;BR /&gt;Thank you for your help!</description>
      <pubDate>Tue, 01 Feb 2022 23:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793930#M254525</guid>
      <dc:creator>seohyeonjeong</dc:creator>
      <dc:date>2022-02-01T23:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793931#M254526</link>
      <description>Thank you for your help.&lt;BR /&gt;How generous you are. Thank you for the examples. It is easy to understand.</description>
      <pubDate>Tue, 01 Feb 2022 23:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793931#M254526</guid>
      <dc:creator>seohyeonjeong</dc:creator>
      <dc:date>2022-02-01T23:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an excel function =IF(B1=B2, 0, 1) in SAS PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793932#M254527</link>
      <description>I truly understand what you mean. It's really annoying that I have to use only PROC SQL.&lt;BR /&gt;I will ask my boss to do this on normal SAS and will change the code when we move this one to AWS Athena. Thank you for your help:)</description>
      <pubDate>Tue, 01 Feb 2022 23:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-an-excel-function-IF-B1-B2-0-1-in-SAS-PROC-SQL/m-p/793932#M254527</guid>
      <dc:creator>seohyeonjeong</dc:creator>
      <dc:date>2022-02-01T23:29:49Z</dc:date>
    </item>
  </channel>
</rss>

