<?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: Checking if variables are equal? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198208#M37123</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up just creating new variables ex type 1 error type 2 error type 3 error and so on...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if whichever type of ever is present then set a 1 in the new variable, if sum of new variables &amp;gt;1 then errorType = mixed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jul 2015 20:08:28 GMT</pubDate>
    <dc:creator>jbscholten</dc:creator>
    <dc:date>2015-07-09T20:08:28Z</dc:date>
    <item>
      <title>Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198201#M37116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all, I'm trying to check if certain variables from a dataset are equal or blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are 28 variables that I have, ErrorTypeFV_1, ErrorTypeFV_2, ..... ErrorTypeFV_28, one for each year and each can have 4 values, 1,2,3, or 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically what I want to check is that for all rows, if all ErrorTypeFV_1 through ErrorTypeFV_28 are EQUAL,&amp;nbsp; then to set a new variable, "TYPE" to the value of these variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue is that some of these years 1-28 can be blank, and this is okay. I just want to check that all variables that are not blank are equal.&lt;/P&gt;&lt;P&gt;Additionally, if there are two different values in any row I would like "TYPE" to be set to mixed.&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've an example I constructed in excel, the years after ErrorType are not present.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="&amp;lt;/span" /&gt;&lt;A class="jive-link-external-small" href="http://i59.tinypic.com/sm9bbt.png&amp;gt;"&gt;http://i59.tinypic.com/sm9bbt.png[/IMG]&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 12:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198201#M37116</guid>
      <dc:creator>jbscholten</dc:creator>
      <dc:date>2015-07-08T12:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198202#M37117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well you could use arrays:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array errortypefv_{28};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type=errortypefv_{1};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=2 to 28;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if errortypefv_{i} ne . and type ne errortypefv_{i} then type=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;You can put any checking in the do loop, I just stated set type to first value, then if not missing, and not equal to the first value then set type to missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, please post test data in the form of a datastep, that picture is unhelpful and looks like a dodgy website.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 13:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198202#M37117</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-08T13:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198203#M37118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see, thank you RW9. I've never worked with arrays.&lt;/P&gt;&lt;P&gt;After checking, this works, but ONLY if errortypefv_1 is not blank.&amp;nbsp; If FV_1 is blank then type is returning blank as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 13:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198203#M37118</guid>
      <dc:creator>jbscholten</dc:creator>
      <dc:date>2015-07-08T13:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198204#M37119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, RW9! Never worked with arrays before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works, however only for rows in which errortypeFV_1 is not blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need this to pick up the first populated errorType field. and then check if the rest are the same.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 13:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198204#M37119</guid>
      <dc:creator>jbscholten</dc:creator>
      <dc:date>2015-07-08T13:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198205#M37120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Slight modification then (note I can't check this at the moment - unsure about the whichn syntax from memory):&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array errortypefv_{28};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type=errortypefv_{whichn(&amp;gt; .,of errortypefv_{*})};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if whichn(!= type,of errortypefv_{*}) &amp;gt; 0 then flag=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the above doesn't work (and will check it tomorrow), then just use loops:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array errortypefv_{28};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until (type ne . or i &amp;gt; 28);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if errortypefv_{i} &amp;gt; . then type=errortypefv_{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 28;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if errortypefv_{i} ne . and errortypefv_{i} ne type then flag=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 17:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198205#M37120</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-08T17:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198206#M37121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just to follow up, that's not the syntax of whichn.&amp;nbsp; However I did think up this little bit of code:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines dlm=",";&lt;/P&gt;&lt;P&gt;&amp;nbsp; input errortypefv_1-errortypefv_5;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;.,.,5,.,5&lt;/P&gt;&lt;P&gt;1,2,3,4,5&lt;/P&gt;&lt;P&gt;.,2,2,2,.&lt;/P&gt;&lt;P&gt;2,.,.,.,2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=tmp);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array errortypefv_{5};&lt;/P&gt;&lt;P&gt;&amp;nbsp; tmp=compress(cats(of errortypefv_{*}),".");&lt;/P&gt;&lt;P&gt;&amp;nbsp; if lengthn(compress(tmp,substr(tmp,1,1))) &amp;gt; 0 then flag=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically it create a string of your numbers, removes the missings, then removes all occurrences of the first character, anything left indicates there is a difference. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 09:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198206#M37121</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-09T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198207#M37122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just do&lt;/P&gt;&lt;P&gt;if min(of ErrorTypeFV:) = max(of ErrorTypeFV:);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 11:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198207#M37122</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-07-09T11:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198208#M37123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up just creating new variables ex type 1 error type 2 error type 3 error and so on...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if whichever type of ever is present then set a 1 in the new variable, if sum of new variables &amp;gt;1 then errorType = mixed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 20:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198208#M37123</guid>
      <dc:creator>jbscholten</dc:creator>
      <dc:date>2015-07-09T20:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if variables are equal?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198209#M37124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you would still be better off normalising the data, then you can just use aggregates:&lt;/P&gt;&lt;P&gt;errortypefv_no&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errortypefv_result&lt;/P&gt;&lt;P&gt;1&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; .&lt;/P&gt;&lt;P&gt;2&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; 1&lt;/P&gt;&lt;P&gt;3&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; 2&lt;/P&gt;&lt;P&gt;4&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; .&lt;/P&gt;&lt;P&gt;5&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; .&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Depending on what else you do with the data can also help further on as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 07:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-variables-are-equal/m-p/198209#M37124</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-10T07:57:51Z</dc:date>
    </item>
  </channel>
</rss>

