<?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 value between two different columns for entire datasets and calculate overall score in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884174#M349276</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357256"&gt;@abraham1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as your sample dataset TESTING with its &lt;EM&gt;pairs of variables next to each other&lt;/EM&gt; is representative for your real data, you could transpose the data from wide to long and finally back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Change the data structure from wide to long */

proc transpose data=testing out=long;
by pid visit;
run;

/* Compute the índividual scores */

data complong(drop=_: col1);
set long;
by pid visit;
if first.visit then suffix=0;
_m=mod(_n_-1,2);
suffix+_m;
score = col1=1 &amp;amp; lag(col1)=1;
if _m;
run;

/* Create wide output dataset and compute sum score */

proc transpose data=complong out=compwide(drop=_:) prefix=score;
by pid visit;
var score;
id suffix;
run;

data want;
set compwide;
sum_score=sum(of score:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The individual scores are now named SCORE1, SCORE2, etc. for simplicity. If needed, you can rename or label them based on the names of the original variables.&lt;/P&gt;
&lt;P&gt;(Note the inconsistency "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;&lt;STRONG&gt;jp&lt;/STRONG&gt;&lt;/EM&gt;_score&lt;/FONT&gt;" vs. "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/EM&gt;_score&lt;/FONT&gt;" in your COMP dataset.)&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2023 12:37:05 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-07-10T12:37:05Z</dc:date>
    <item>
      <title>Compare value between two different columns for entire datasets and calculate overall score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884167#M349272</link>
      <description>&lt;P&gt;Hello Everyone!&lt;/P&gt;
&lt;P&gt;In my below datasets, I need to compare between two unique columns (jp1~jp2, eye1~eye2 etc) and calculate value based on condition as&amp;nbsp; if both contain value of 1, then display as 1 else zero.&lt;/P&gt;
&lt;P&gt;Once done, sum all the score from derived columns.&lt;/P&gt;
&lt;P&gt;In my actual datasets, I have two hundred columns with different name (not end with suffix 1 or 2)&lt;/P&gt;
&lt;P&gt;and I need to follow below approach,&lt;/P&gt;
&lt;P&gt;Is there any alternative way to program it.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
input pid visit jp1 jp2 eye1 eye2 ear1 ear2 nose1 nose2;
cards;
101 2 1 1 1 1 1 0 0 1
102 3 0 0 1 0 1 1 1 1
102 5 0 0 1 0 1 1 0 0
102 6 1 1 1 1 1 1 1 1
103 4 0 0 0 0 0 0 1 1
104 7 1 1 1 1 1 1 1 0
105 3 . 0 0 . . . . .
;
run;
data comp;
set testing;
by pid visit;
if jp1=1 and jp2 =1 then jp_score=1; else f_score=0;
if eye1=1 and eye2 =1 then eye_score=1 ;else eye_score=0;
if ear1=1 and ear2 =1 then ear_score=1; else ear_score=0;
if nose1=1 and nose2 =1 then nos_score=1; else nos_score=0;
sum_score=sum(f_score,eye_score,ear_score,nos_score);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2023 11:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884167#M349272</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2023-07-10T11:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Compare value between two different columns for entire datasets and calculate overall score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884168#M349273</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I have two hundred columns with different name (not end with suffix 1 or 2).&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is a complication. If it had not been for the above, ARRAY would work well. However, what are the real variable names? Are the two variables to compare always next to each other with relatively similar names, or are the names not similar so that one such variable is named (for example) COPN and the variable it is supposed to be compared with named FROGZ12 (which is not at all similar to the variable name COPN) and is not next to COPN? We need details here.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 11:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884168#M349273</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-10T11:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Compare value between two different columns for entire datasets and calculate overall score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884170#M349275</link>
      <description>Variable are totally different like SOTMIGT with TOSDIGT,  DOBINEE~EDTANEE, AIKTNEE~WSTINEE, CHOSTEAD~DEENEAD etc. Most of variable last three letters are same when selected for comparison</description>
      <pubDate>Mon, 10 Jul 2023 12:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884170#M349275</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2023-07-10T12:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compare value between two different columns for entire datasets and calculate overall score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884174#M349276</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357256"&gt;@abraham1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as your sample dataset TESTING with its &lt;EM&gt;pairs of variables next to each other&lt;/EM&gt; is representative for your real data, you could transpose the data from wide to long and finally back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Change the data structure from wide to long */

proc transpose data=testing out=long;
by pid visit;
run;

/* Compute the índividual scores */

data complong(drop=_: col1);
set long;
by pid visit;
if first.visit then suffix=0;
_m=mod(_n_-1,2);
suffix+_m;
score = col1=1 &amp;amp; lag(col1)=1;
if _m;
run;

/* Create wide output dataset and compute sum score */

proc transpose data=complong out=compwide(drop=_:) prefix=score;
by pid visit;
var score;
id suffix;
run;

data want;
set compwide;
sum_score=sum(of score:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The individual scores are now named SCORE1, SCORE2, etc. for simplicity. If needed, you can rename or label them based on the names of the original variables.&lt;/P&gt;
&lt;P&gt;(Note the inconsistency "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;&lt;STRONG&gt;jp&lt;/STRONG&gt;&lt;/EM&gt;_score&lt;/FONT&gt;" vs. "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/EM&gt;_score&lt;/FONT&gt;" in your COMP dataset.)&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 12:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884174#M349276</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-10T12:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Compare value between two different columns for entire datasets and calculate overall score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884175#M349277</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357256"&gt;@abraham1&lt;/a&gt;&amp;nbsp;I need to know if the variables to compare are consecutive in the data set, or can they be widely separated. Please answer.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 12:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-value-between-two-different-columns-for-entire-datasets/m-p/884175#M349277</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-10T12:47:57Z</dc:date>
    </item>
  </channel>
</rss>

