<?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 check one variables value in another variable in same dataset irresepctive of its row ord in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433183#M107381</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190664"&gt;@Priya_26&lt;/a&gt;&amp;nbsp;With no surprises, the genius Ksharp gave you the hash solution even before I woke up to see your message. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 17:05:20 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-02-01T17:05:20Z</dc:date>
    <item>
      <title>How to check one variables value in another variable in same dataset irresepctive of its row order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433009#M107302</link>
      <description>&lt;P&gt;Hello Everyone !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4 Version.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one dataset as below and I want to check if VarA's value in present in VarB anywhere, irrespective of its row order.based on the i can create a new variable to mark yes/No based on its presence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help how can i check it in sas using datastep /Macro/proc sql ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to search if XX is present in VarB anywhere ? if yes then mark it as Y else NO&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if YY is present in VarB anywhere ? if yes then mark it as Y else NO and so on .. till the dataset ends.&lt;BR /&gt;&lt;BR /&gt;Dataset- Test&lt;BR /&gt;VarA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VarB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_var&lt;/P&gt;&lt;P&gt;&amp;nbsp;XX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;YY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; N&lt;/P&gt;&lt;P&gt;&amp;nbsp;ZZ&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;N&lt;BR /&gt;AA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Y&lt;BR /&gt;BB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433009#M107302</guid>
      <dc:creator>Priya_26</dc:creator>
      <dc:date>2018-02-01T06:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433012#M107303</link>
      <description>&lt;P&gt;using Hash object is very easy if you know it,and since you didn't mention, I am giving you the more traditional datastep solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (VarA     VarB) ($);       
datalines;
 XX         PP             
 YY         MM             
 ZZ          XX              
AA           BB              
BB           AA              
;

proc transpose data=have(keep=varb) out=_have;
var varb;
run;

data want;
set have;
if _n_=1 then set _have;
array t(*) col:	;
if vara in t then new_var="Y";
else new_var="N";
keep vara varb new_var;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433012#M107303</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-01T06:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433016#M107305</link>
      <description>&lt;P&gt;My preference:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select distinct(quote(varb)) into : b_list separated by ' ' from have;&lt;/P&gt;
&lt;P&gt;quit;&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;if vara in (&amp;amp;b_list) then new_var='Y';&lt;/P&gt;
&lt;P&gt;else new_var='N';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433016#M107305</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-01T06:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433017#M107306</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s approach will work comfortably for&amp;nbsp; relatively medium sized datasets however if you are working with very large datasets and the macro var list(if and when exceeds 64k length) as it did once to me in a similar situation will make you look for an alternative solution yet again.&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433017#M107306</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-01T06:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433020#M107309</link>
      <description>&lt;P&gt;And Proc SQL:&lt;/P&gt;&lt;P&gt;Proc sql does not guarantee the order of the output though:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (VarA     VarB) ($);       
datalines;
 XX         PP             
 YY         MM             
 ZZ          XX              
AA           BB              
BB           AA              
;

proc sql;
create table want as
select a.* ,max(case when a.vara=b.varb then 'Y' else 'N' end) as new_var
from have a, have(keep=varb) b
group by a.vara,a.varb;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433020#M107309</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-01T06:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433022#M107311</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table test1 as
    select t.*, 
    (case when (select count(*) from test where VarB =t.VarA) =0 then 'N' 
            else 'Y' end) as new_var
  from test t;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will work.&lt;BR /&gt;It will work like a charm until the size of the DS in small or medium or you have an index on VarB.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 07:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433022#M107311</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-01T07:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433025#M107313</link>
      <description>&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;VarA VarB&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;XX PP &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;YY MM &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;ZZ XX &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;AA BB &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;BB AA &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;run;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct("varb") into : mac separated by ' ' from have;&lt;/P&gt;&lt;P&gt;quit;&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;if vara in (&amp;amp;mac) then new_var='Y';&lt;/P&gt;&lt;P&gt;else new_var='N';&lt;/P&gt;&lt;P&gt;run;&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;</description>
      <pubDate>Thu, 01 Feb 2018 07:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433025#M107313</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-02-01T07:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433042#M107322</link>
      <description>&lt;P&gt;Hi Novinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your answer. I didn't know that even a single dataset can be looked for different variables within.&lt;BR /&gt;&lt;BR /&gt;Can you please suggest the HASH object suggestion for same&amp;nbsp; ?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 09:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433042#M107322</guid>
      <dc:creator>Priya_26</dc:creator>
      <dc:date>2018-02-01T09:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433089#M107343</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (VarA     VarB) ($);       
datalines;
 XX         PP             
 YY         MM             
 ZZ          XX              
AA           BB              
BB           AA              
;
data want;
 if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('varb');
  h.definedone();
 end;
 set have;
 if h.check(key:vara)=0 then flag='Y';
  else flag='N';
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 12:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433089#M107343</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-01T12:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433183#M107381</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190664"&gt;@Priya_26&lt;/a&gt;&amp;nbsp;With no surprises, the genius Ksharp gave you the hash solution even before I woke up to see your message. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433183#M107381</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-01T17:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433377#M107439</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;Thank you veru much for your time and Solution. Both of them are just working Perfect. Since I have to use this in production with Huge data as input, I will go with HASH solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 05:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433377#M107439</guid>
      <dc:creator>Priya_26</dc:creator>
      <dc:date>2018-02-02T05:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to check one variables value in another variable in same dataset irresepctive of its row ord</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433378#M107440</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;Thanks alot, This is just perfect &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you veru much !! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 05:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-one-variables-value-in-another-variable-in-same/m-p/433378#M107440</guid>
      <dc:creator>Priya_26</dc:creator>
      <dc:date>2018-02-02T05:00:47Z</dc:date>
    </item>
  </channel>
</rss>

