<?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: Mark obeservations which fulfill specific conditions in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513558#M6587</link>
    <description>&lt;P&gt;something like below in SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select name
,dummy_x
,case when count(dummy_x) -sum(dummy_x) = 0 then "N"
else "Y"
end as Both
from have
group by 1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Nov 2018 20:00:25 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2018-11-15T20:00:25Z</dc:date>
    <item>
      <title>Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513541#M6583</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have a data set with dummy variables and would like to know which of the observations take&amp;nbsp;BOTH values "1" and "0".&lt;/P&gt;&lt;P&gt;Column "Name" and "Dummy X" are already in my data set. Now I would like to add the Column "BOTH" to the data set. If an observation in Column "Name" hast taken both values "1" and "0" , then give me a "YES" in the new column, otherwise a "NO" (this would be the case in this example&amp;nbsp;for "Jorge" and "Tim"&amp;nbsp;since they are the only ones who have taken both values of&amp;nbsp;"1" and "0"). Background: I would like to consider in a different sample only the observations with "YES".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;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/TR&gt;&lt;TR&gt;&lt;TD&gt;Sarah&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Johanna&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 19:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513541#M6583</guid>
      <dc:creator>jozuleta</dc:creator>
      <dc:date>2018-11-15T19:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513554#M6585</link>
      <description>&lt;P&gt;If you sort your data by NAME DUMMYX with option NODUPKEY you will get per name either one observation (DUMMYX is either 1 or 0)&amp;nbsp;or two observations (both 1 and 0) :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=temp nodupkey;
  by name dummyx;
run;
data want;
 set temp;
   by name;
       if not (first.name and last.name) then both='YES';
       else both='NO';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Nov 2018 19:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513554#M6585</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-15T19:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513555#M6586</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $	DummyX ;	
cards;
Jorge	1	YES
Marc	1	NO
Ben	1	NO
Tim	1	YES
Jorge	0	YES
Marc	1	NO
Ben 	1	NO
Tim	0	YES
Jorge	0	YES
Marc	1	NO
Sarah	1	NO
Johanna	0	NO
;
data temp;
set have;
n+1;
run;

proc sql;
create table want(drop=n) as
select *,ifc(count (distinct DummyX)&amp;gt;1,'YES','NO') as Both
from temp
group by name
order by n;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Nov 2018 19:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513555#M6586</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-15T19:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513558#M6587</link>
      <description>&lt;P&gt;something like below in SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select name
,dummy_x
,case when count(dummy_x) -sum(dummy_x) = 0 then "N"
else "Y"
end as Both
from have
group by 1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Nov 2018 20:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513558#M6587</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-15T20:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513640#M6591</link>
      <description>&lt;P&gt;I would recommend to stop thinking in terms of "Yes" and 'NO' but 1 and 0 for a number of reasons. Some analysis procedures require numeric values. And you can always have a custom format display 1 and 0 as needed.&lt;/P&gt;
&lt;P&gt;With that in mind:&lt;/P&gt;
&lt;PRE&gt;data example;
 input Name $ Dummy ;
datalines;
Jorge 1  
Marc 1  
Ben 1 
Tim 1 
Jorge 0  
Marc 1 
Ben  1 
Tim 0  
Jorge 0  
Marc 1  
Sarah 1  
Johanna 0 
;
run;

proc sql;
   create table want as
   select name, dummy,  range(dummy) as both 
   from example 
   group by name;
quit;&lt;/PRE&gt;
&lt;P&gt;The RANGE function subtracts the smallest value from the largest. If all of the values are the same the result is 0 (so no which is typical interpretation of 0). Since your values for the dummy variable are 1 and 0 you only get a 1 when both values occur somewhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you could even filter the data at this step:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select name, dummy,  range(dummy) as both 
   from example 
   group by name
   having both;
quit;&lt;/PRE&gt;
&lt;P&gt;SAS treats 0 as false for comparisons so those that are not "both" are not in the output set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 21:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513640#M6591</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-15T21:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513642#M6592</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Ultraclever !!!!!!!!!,&amp;nbsp; &amp;nbsp;is blood running in your body ior s it brains running all over?. Why such ideas not striking my mind&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 21:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513642#M6592</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-15T21:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513661#M6593</link>
      <description>Awesome!</description>
      <pubDate>Thu, 15 Nov 2018 21:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513661#M6593</guid>
      <dc:creator>jozuleta</dc:creator>
      <dc:date>2018-11-15T21:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Mark obeservations which fulfill specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513684#M6596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Ultraclever !!!!!!!!!,&amp;nbsp; &amp;nbsp;is blood running in your body ior s it brains running all over?. Why such ideas not striking my mind&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mostly 32 years of SAS experience and sometimes a twisted approach to specific sorts of problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An assembler class I took many years ago had a class assignment of reversing the digits of a number. The professor expected some sort of MOD function to find the lower order digit, save,&amp;nbsp;and then multiply (or shift register) and repeat until you ran of digits. I used a buffer manipulation that would reverse anything that fit, character or numeric. Still a loop but entirely different.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 22:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Mark-obeservations-which-fulfill-specific-conditions/m-p/513684#M6596</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-15T22:10:14Z</dc:date>
    </item>
  </channel>
</rss>

