<?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: Check if IDs have always the same value of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835226#M330202</link>
    <description>It seems I cannot edit. Briefly: suppose to have a file that looks like this: &lt;BR /&gt;   ID        Value     &lt;BR /&gt;    a            54            &lt;BR /&gt;    a            54   &lt;BR /&gt;    a            54   &lt;BR /&gt;    a            54   &lt;BR /&gt;    b            54   &lt;BR /&gt;    b            32&lt;BR /&gt;    b            54&lt;BR /&gt;&lt;BR /&gt;and you want to for example add a label in a new column that contains 1 only for ID =a that has only and always 54 in column value</description>
    <pubDate>Mon, 26 Sep 2022 17:16:14 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2022-09-26T17:16:14Z</dc:date>
    <item>
      <title>Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835217#M330194</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there a way to check, for each ID if the value of a variable is always the same like for example 54?&lt;/P&gt;
&lt;P&gt;I would like to do an if statement only for those IDs where the value of variable x is only and always 54.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 16:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835217#M330194</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-09-26T16:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835218#M330195</link>
      <description>&lt;P&gt;Your question is a little hard to understand.&amp;nbsp; I suggest you edit your question to include a small amount of sample data (like 10 rows), and describe which records you want&amp;nbsp; to select with your IF statement, and why.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 16:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835218#M330195</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-26T16:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835220#M330197</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class id;
    var x;
    output out=_stats_ min=x_min max=x_max;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, if the x_min and x_max are the same value, that would meet your desired condition of all the same value of x. So that would involve doing a comparison. You can take this idea one step further and eliminate the need to do a comparison with this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output out=_stats_ range=x_range;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and if the x_range is zero, then all the x-values are the same.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 16:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835220#M330197</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-26T16:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835226#M330202</link>
      <description>It seems I cannot edit. Briefly: suppose to have a file that looks like this: &lt;BR /&gt;   ID        Value     &lt;BR /&gt;    a            54            &lt;BR /&gt;    a            54   &lt;BR /&gt;    a            54   &lt;BR /&gt;    a            54   &lt;BR /&gt;    b            54   &lt;BR /&gt;    b            32&lt;BR /&gt;    b            54&lt;BR /&gt;&lt;BR /&gt;and you want to for example add a label in a new column that contains 1 only for ID =a that has only and always 54 in column value</description>
      <pubDate>Mon, 26 Sep 2022 17:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835226#M330202</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-09-26T17:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835233#M330208</link>
      <description>&lt;P&gt;Is the value 54 part of the criteria or is the criteria just constant value within an ID?&amp;nbsp; So if you had:&lt;/P&gt;
&lt;PRE&gt;ID Value
a 54
a 54
a 54
a 54
b 54
b 32
b 54
c 32
c 32&lt;/PRE&gt;
&lt;P&gt;Would you want to flag id=c?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show what code you have tried?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you comfortable with SQL?&amp;nbsp; Are you familiar with data step DOW-loop pattern?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 17:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835233#M330208</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-26T17:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835237#M330211</link>
      <description>&lt;P&gt;Adding to my earlier reply, this will give you a column of ones (when the value of x is constant) and zeros (when the value of x is not constant).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     merge have _stats_;
     by id;
     new_column = (x_range=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 17:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835237#M330211</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-26T17:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Check if IDs have always the same value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835264#M330228</link>
      <description>&lt;P&gt;Here's a SQL approach.&amp;nbsp; This makes use of the fact that PROC SQL will 'remerge' automatically, which many SQL folks don't like.&amp;nbsp; Not sure how you want to handle missing values.&amp;nbsp; This will not treat a missing value as different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input id $1 Value ;
  cards ;
a 54
a 54
a 54
a 54
b 54
b 32
b 54
c 32
c 32
d 60
d .
e .
e .
;

proc sql ;
  select id,Value,range(value)=0 as Constant 
  from have
  group by id
  ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;id     Value  Constant
----------------------
a         54         1
a         54         1
a         54         1
a         54         1
b         54         0
b         32         0
b         54         0
c         32         1
c         32         1
d          .         1
d         60         1
e          .         0
e          .         0
&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 19:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-IDs-have-always-the-same-value-of-a-variable/m-p/835264#M330228</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-26T19:41:31Z</dc:date>
    </item>
  </channel>
</rss>

