<?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: Operators in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829724#M327831</link>
    <description>NOT IN is correct, but I suspect those values are character not numeric so you would need to include them in quotes. &lt;BR /&gt;&lt;BR /&gt;If you're having issues, post your code/log.</description>
    <pubDate>Mon, 22 Aug 2022 19:27:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-08-22T19:27:25Z</dc:date>
    <item>
      <title>Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829723#M327830</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I will like to create a variable &lt;STRONG&gt;Zip_1&lt;/STRONG&gt; where:&lt;/P&gt;&lt;P&gt;1 = Response zip code does NOT correlate to a state zip code&lt;/P&gt;&lt;P&gt;0 = Response zip code correlates to a state zip cod.&lt;/P&gt;&lt;P&gt;I used the following data step;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;set b;&lt;/P&gt;&lt;P&gt;if zipcode in (45666,55756,33546,45645,08083) then &lt;STRONG&gt;Zip_1&lt;/STRONG&gt; =0;&lt;/P&gt;&lt;P&gt;else &lt;STRONG&gt;Zip_1&lt;/STRONG&gt;=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I use the operator (not in) so that I can have &lt;STRONG&gt;Zip_1&lt;/STRONG&gt;=1 before &lt;STRONG&gt;Zip_1&lt;/STRONG&gt;=0. I guess what am trying to ask is what is the correct operator for (not in) so that I will be able to include all the numbers.&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;set b;&lt;/P&gt;&lt;P&gt;if zipcode&amp;nbsp; not in (45666,55756,33546,45645,08083)&lt;/P&gt;&lt;P&gt;then &lt;STRONG&gt;Zip_1&lt;/STRONG&gt; =0;&lt;/P&gt;&lt;P&gt;else &lt;STRONG&gt;Zip_1&lt;/STRONG&gt;=1; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829723#M327830</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2022-08-22T19:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829724#M327831</link>
      <description>NOT IN is correct, but I suspect those values are character not numeric so you would need to include them in quotes. &lt;BR /&gt;&lt;BR /&gt;If you're having issues, post your code/log.</description>
      <pubDate>Mon, 22 Aug 2022 19:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829724#M327831</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-22T19:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829728#M327835</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; Is there a quick way to include quotes in all the numbers without manually doing it one after the other. I have a-lot of zip-codes and its time consuming. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829728#M327835</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2022-08-22T19:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829729#M327836</link>
      <description>&lt;P&gt;If the list of zip codes is in a SAS data set, you can create a macro variable that has all the desired quotes and commas very easily.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct quote(cats(zipcode)) into :zipcodes separated by ',' from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then use the macro variable &amp;amp;zipcodes as your list of zip codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALTERNATIVE&lt;/P&gt;
&lt;P&gt;You can use the editor Find/Replace function, select the desired sequence of code, the find a single comma and replace it with ',' (thats quote-comma-quote), and click on Replace in Selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will leave some cleanup to do manually, the first and last quote will not be present, and line breaks will need to be fixed as well.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829729#M327836</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-22T20:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829734#M327840</link>
      <description>&lt;P&gt;Where are these zipcodes stored? If you have them in a data set or table, perhaps a join or format is a better approach than manually typing out a list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, confirm your variable type by looking at the proc contents of your data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829734#M327840</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-22T20:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829737#M327841</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;Thank you but I really do not understand how you wanted me to do it. I have initially thought about the find and replace but not sure how it will work. Am finding it hard to follow through with your wording, may be you can help me clarify it better.&lt;/P&gt;&lt;P&gt;This is how my code is setup:&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;set b;&lt;/P&gt;&lt;P&gt;if Zipcode NOT IN&lt;BR /&gt;(21501,21502,21503,21504,21505&lt;BR /&gt;21521,21524,21528,21529,21530&lt;BR /&gt;21532,21539,21540,21542,21543&lt;BR /&gt;21545,21555,21556,21557,21560&lt;BR /&gt;21562,21766,20711,20724,20733&lt;BR /&gt;20751,20755,20758,20764,20765&lt;BR /&gt;20776,20778,20779,21012,21032) then zip_1=0;&lt;/P&gt;&lt;P&gt;else zip_1=1;run;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829737#M327841</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2022-08-22T20:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829739#M327843</link>
      <description>&lt;P&gt;Select all the zipcodes and commas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then Find all the commas, replace with ',' (quote-comma-quote) and then click on Replace in Selected, then do a manual cleanup&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although I think the SQL code I posted is even easier and more fool-proof, if the zip codes are in a SAS data set.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 20:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829739#M327843</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-22T20:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829753#M327846</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/253321"&gt;@CathyVI&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; Is there a quick way to include quotes in all the numbers without manually doing it one after the other. I have a-lot of zip-codes and its time consuming. Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or if &lt;STRONG&gt;all&lt;/STRONG&gt; of your Zip code variable values are 5 digits you could convert that to numeric for the comparison:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if input(zipcode,5.) in (&amp;lt;list written without quotes as numeric values&amp;gt;) then ...;&lt;/PRE&gt;
&lt;P&gt;BTW if the Zipcode variable is character you may have seen a note in the log about "numeric values converted to character" for the comparison. Which would typically fail the comparisons as the default conversion that SAS applied in the background would likely have had 7 leading spaces using a BEST12 conversion and the 5 digits in the character stopped comparing as unequal because the first space didn't match the Zip value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach if the list of Zips of interest is fairly static would be to create a custom informat with the INPUT function to create the numeric value you want. An example:&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue myziplist
'45666','55756','33546','45645','08083' = 0
other = 1
;

data example;
  input zip $5.;
  zip_1 = input(zip,myziplist.);
datalines;
45666
55756
33546
45645
08083
44444
55555
;&lt;/PRE&gt;
&lt;P&gt;If you happen to have a list of the values you want in a data set then it would likely be very easy to create a CNTLIN data set for Proc Format to use that. Which may be helpful if this list is not static. If the list is "very large", not sure where the boundary may be, the Informat may be quicker than a very large IN comparison as well.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 21:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829753#M327846</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-22T21:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Operators in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829800#M327863</link>
      <description>&lt;P&gt;Where does the list of valid zip codes come from? From a text file hopefully.&lt;/P&gt;
&lt;P&gt;If this is the case:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;import that file using a data step,&lt;/LI&gt;
&lt;LI&gt;read the docs about creating a format from a dataset (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm&lt;/A&gt;)&lt;/LI&gt;
&lt;LI&gt;define an informat to convert valid zip codes to 0 and anything else to 1&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 23 Aug 2022 06:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Operators-in-sas/m-p/829800#M327863</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-08-23T06:49:03Z</dc:date>
    </item>
  </channel>
</rss>

