<?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: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519443#M140684</link>
    <description>&lt;P&gt;Many thanks to you guys for your replies, I realize I should have specified since it makes a difference that my real data has numbers instead of letters so something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Q1&lt;/TD&gt;&lt;TD&gt;Q2&lt;/TD&gt;&lt;TD&gt;Q3&lt;/TD&gt;&lt;TD&gt;Q4&lt;/TD&gt;&lt;TD&gt;Q5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Correct Answer&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to replace the fields with new data, I'll want to create a new dataset, with the correct answer and candidate numbers, and then after that, I'll want to calculate the percentage of answers that are correct for each question, maybe transposing the data and using Proc Freq&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
    <pubDate>Fri, 07 Dec 2018 15:27:42 GMT</pubDate>
    <dc:creator>AJChamberlain</dc:creator>
    <dc:date>2018-12-07T15:27:42Z</dc:date>
    <item>
      <title>Compare the value of an observation in row 1 to the value in subsequent rows for the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519437#M140679</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of exam candidates with multiple choice test answers (A-D) which looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Q1&lt;/TD&gt;&lt;TD&gt;Q2&lt;/TD&gt;&lt;TD&gt;Q3&lt;/TD&gt;&lt;TD&gt;Q4&lt;/TD&gt;&lt;TD&gt;Q5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Correct Answer&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 1&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where 3 candidates have taken a multiple choice test, and the correct answer is in row 1, their answers in each subsequent row. I need some code to read the correct answer from row 1 for each question and return a '1' for a correct answer and a '0' for a wrong answer some something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Output&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Q1&lt;/TD&gt;&lt;TD&gt;Q2&lt;/TD&gt;&lt;TD&gt;Q3&lt;/TD&gt;&lt;TD&gt;Q4&lt;/TD&gt;&lt;TD&gt;Q5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 3&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I've found lots of examples of code to compare to a previous row but all my rows from 2 onwards need to compare to row one, and I need to do this for each variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519437#M140679</guid>
      <dc:creator>AJChamberlain</dc:creator>
      <dc:date>2018-12-07T15:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519439#M140681</link>
      <description>&lt;P&gt;One good way:&amp;nbsp; create a temporary array from the values in the first observation.&amp;nbsp; Then compare on later observations to the values in the array.&amp;nbsp; You cannot replace Q1-Q5 with 0/1 values.&amp;nbsp; They are character, not numeric.&amp;nbsp; So you will need to create a new set of numeric variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array correct {5} $ 1 _temporary_;&lt;/P&gt;
&lt;P&gt;array q {5} q1-q5;&lt;/P&gt;
&lt;P&gt;array num {5} n1-n5;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do k=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;correct{k} = q{k};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do k=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;num{k} = (correct{k} = q{k});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519439#M140681</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-07T15:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519440#M140682</link>
      <description>&lt;P&gt;Use RETAIN to create variable that is kept until reset. Then only set the values on the first record.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   retain correctQ1 - correctq5;
   if _n_=1 then do;
      correctq1 = q1;
      correctq2 = q2;
      /*follow the obvious pattern*/
   end;
   else do;
      q1 = put( (q1=correctq1),f1.);
      /* other comparisons similar*/
      output;
   end;
   drop correct: ;
run;&lt;/PRE&gt;
&lt;P&gt;Of course since your Q1 to Q5 are originally character then final result, unless you jump through some hoops, will be character for final Q1 - Q5 variables. I used the put to avoid log notes about conversion from numeric to character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519440#M140682</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-07T15:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519441#M140683</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var &amp;amp; $15. (Q1	Q2	Q3	Q4	Q5) (:$1.);
cards;
Correct Answer		A	C	D	B	C
Candidate 1		C	C	A	B	A
Candidate 2		A	C	C	B	C
Candidate 3		B  	A	B	B	B
;
data want;
set have;
array qq(*) q:;
array t(5)$1 _temporary_;;
array _q(5);
if _n_=1 then
do i=1 to dim(qq);
t(i)=qq(i);
end;
if _n_&amp;gt;1;
do i=1 to dim(t);
_q(i)=t(i)=qq(i);
end;
drop q: i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519441#M140683</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T15:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519443#M140684</link>
      <description>&lt;P&gt;Many thanks to you guys for your replies, I realize I should have specified since it makes a difference that my real data has numbers instead of letters so something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Q1&lt;/TD&gt;&lt;TD&gt;Q2&lt;/TD&gt;&lt;TD&gt;Q3&lt;/TD&gt;&lt;TD&gt;Q4&lt;/TD&gt;&lt;TD&gt;Q5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Correct Answer&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Candidate 3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to replace the fields with new data, I'll want to create a new dataset, with the correct answer and candidate numbers, and then after that, I'll want to calculate the percentage of answers that are correct for each question, maybe transposing the data and using Proc Freq&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519443#M140684</guid>
      <dc:creator>AJChamberlain</dc:creator>
      <dc:date>2018-12-07T15:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519444#M140685</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var &amp;amp; $15. Q1	Q2	Q3	Q4	Q5 ;
cards;
Correct Answer	1	3	4	2	3
Candidate 1		3	3	1	2	1
Candidate 2		1	3	3	2	3
Candidate 3		2	1	2	2	2
;
data want;
set have;
array qq(*) q:;
array t(5) _temporary_;;
if _n_=1 then
do i=1 to dim(qq);
t(i)=qq(i);
end;
if _n_&amp;gt;1;
do i=1 to dim(t);
qq(i)=t(i)=qq(i);
end;
drop  i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519444#M140685</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519446#M140687</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var &amp;amp; $15. Q1	Q2	Q3	Q4	Q5 ;
cards;
Correct Answer	1	3	4	2	3
Candidate 1		3	3	1	2	1
Candidate 2		1	3	3	2	3
Candidate 3		2	1	2	2	2
;
data want;
set have;
array qq(*) q:;
array t(5)  _temporary_;
if _n_=1 then call pokelong(peekclong(addrlong(qq(1)),40),addrlong(t(1)),40);
if _n_&amp;gt;1;
do i=1 to dim(t);
qq(i)=t(i)=qq(i);
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 15:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519446#M140687</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T15:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519461#M140694</link>
      <description>&lt;P&gt;Try One-Many join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select a.var,
		case when a.Q1=b.Q1 then 1 else 0 end as Q1,
		case when a.Q2=b.Q2 then 1 else 0 end as Q2,
		case when a.Q3=b.Q3 then 1 else 0 end as Q3,
		case when a.Q4=b.Q4 then 1 else 0 end as Q4,
		case when a.Q5=b.Q5 then 1 else 0 end as Q5
	from have as a,have as b
where strip(a.var)&amp;lt;&amp;gt;'Correct Answer' and strip(b.var)='Correct Answer'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519461#M140694</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-12-07T16:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519476#M140700</link>
      <description>&lt;P&gt;Your idea may be good, but will not handle efficiently if there are &lt;STRONG&gt;numerous&lt;/STRONG&gt; questions and is pretty much hard coding. Even if you generate tons of case when with macro, the sql processor is not efficient or robust in handling wide datasets. Also, an algorithm is only valid if it can scale from&amp;nbsp; Q1 to Qn (where n&amp;nbsp;should be expected to&amp;nbsp;be a huge number)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course I agree WRT&amp;nbsp; thread, it seems OP has only 5 questions and it doesn't matter but a solution should handle and scale at ease. The thought of proc sql should also pave way to transpose(transform) and then an inner join and boolean, and finally retranspose will suffice, but &lt;STRONG&gt;wide*wide&lt;/STRONG&gt; proc sql would be bizarre for the sql processor/optimizer IMHO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var &amp;amp; $15. Q1	Q2	Q3	Q4	Q5 ;
cards;
Correct Answer	1	3	4	2	3
Candidate 1		3	3	1	2	1
Candidate 2		1	3	3	2	3
Candidate 3		2	1	2	2	2
;
proc transpose data=have out=w;
by var notsorted;
var q:;
run;

proc sql;
create table w1 as
select  a.var,a._name_,a.col1=b.col1 as q
from w(where=(var ne 'Correct Answer')) a, w(where=(var eq 'Correct Answer')) b
where a._name_=b._name_
order by var, _name_;
quit;

proc transpose data=w1 out=want(drop=_name_);
by var notsorted;
var q;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either way, this is not even close the power of temporary array in datastep with a neat one pass solution&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519476#M140700</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T16:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519489#M140704</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input  var &amp;amp; $15. Q1	Q2	Q3	Q4	Q5 ;
cards;
Correct Answer	1	3	4	2	3
Candidate 1		3	3	1	2	1
Candidate 2		1	3	3	2	3
Candidate 3		2	1	2	2	2
;
data want;
set have(where=(var ne 'Correct Answer'));
array qq(*) q:;
if _n_=1 then set have(where=(var eq 'Correct Answer') rename=(q1-q5=t1-t5));
array j(*) t:;
do _n_=1 to dim(j);
qq(_n_)=j(_n_)=qq(_n_);
end;
drop t:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 17:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519489#M140704</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-07T17:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519626#M140777</link>
      <description>&lt;DIV&gt;Using Transpose and array we can get the result:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc transpose&amp;nbsp; data=have out=want name=ID;&lt;BR /&gt;ID ID;&lt;BR /&gt;VAR Q1-Q5;&lt;BR /&gt;run;&lt;/DIV&gt;&lt;DIV&gt;data want;&lt;BR /&gt;set want;&lt;BR /&gt;i=0;&lt;BR /&gt;array Answer(1) Correct_Answer;&lt;BR /&gt;array Candidate(3) Candidate1-Candidate3;&lt;BR /&gt;do i = 1 to 3;&lt;BR /&gt;if Answer[1] = Candidate[i] then do;&lt;BR /&gt;Candidate[i] = 1;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;Candidate[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/DIV&gt;&lt;DIV&gt;proc transpose&amp;nbsp; data=want name=ID;&lt;BR /&gt;ID ID;&lt;BR /&gt;VAR Candidate1-Candidate3;&lt;BR /&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Sat, 08 Dec 2018 04:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519626#M140777</guid>
      <dc:creator>AmarnathEklare</dc:creator>
      <dc:date>2018-12-08T04:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519632#M140782</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've been busy, with many alternatives, and I see you present the advantages of a (1) conditional SET statement.&amp;nbsp; You can also probably dispense with the "where=" options and just use "firstobs=2".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  var &amp;amp; $15. Q1	Q2	Q3	Q4	Q5 ;
cards;
Correct Answer	1	3	4	2	3
Candidate 1		3	3	1	2	1
Candidate 2		1	3	3	2	3
Candidate 3		2	1	2	2	2
;


data want (drop=i ans:);
  if _n_=1 then set have (rename=(q1-q5=ans1-ans5));
  array ans {*} ans:;

  set have (firstobs=2);
  array q {*} q:;

  do i=1 to dim(ans);
    ncorrect=sum(ncorrect,q{i}=ans{i});
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Dec 2018 04:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519632#M140782</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-08T04:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the value of an observation in row 1 to the value in subsequent rows for the same variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519634#M140784</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; Nice one indeed. LOL Yes, I was so bored. That's typical of winter break I suppose and we at DePaul are no different. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; You still awake?&amp;nbsp; I m about to doze off. Cya tomorrow&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 05:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-value-of-an-observation-in-row-1-to-the-value-in/m-p/519634#M140784</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-08T05:02:49Z</dc:date>
    </item>
  </channel>
</rss>

