<?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: MATCHING WITH SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773238#M245603</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;I am not saying that Gender is numeric or character.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Yes you are&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;SPAN&gt;"25" is simply the youngest age in my data set, which ranges from 25 to 76. I do not understand why it gives the error that "where" needs a compatible variable. &lt;FONT color="#FF0000"&gt;Both "age" and "gender" are numeric in my dataset.&lt;/FONT&gt; I double checked to make sure. I am not sure if the "NOTE" above it has somehow converted one of them in a character, and hence the mistake?&lt;/SPAN&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Under similar situation, I would find the type of my variables in the where clause.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I don't know what this means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did removing the quotes fix the error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Oct 2021 22:25:07 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-10-09T22:25:07Z</dc:date>
    <item>
      <title>MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773174#M245566</link>
      <description>&lt;DIV class="gmail_default"&gt;I have used SAS for a few years and I consider myself a relatively&amp;nbsp;good user, but have not done matching before, and I need it for a study.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;I found your paper, and it looks fantastic:&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;A href="https://www.frontiersin.org/articles/10.3389/fdata.2019.00004/full" target="_blank" rel="noopener"&gt;https://www.frontiersin.org/articles/10.3389/fdata.2019.00004/full&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;Mine is a simple&amp;nbsp;clinical dataset. I am basically running it as created above, since the variables "age" and "gender" in my dataset are the same.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;However, I get an error when I run the code, and I don't understand why. Below I will give the code I use, and the error I get.&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;THE CODE:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;BR /&gt;data population;&lt;BR /&gt;set edge;&lt;BR /&gt;if lams_size=1 then casecontrol=1;&lt;BR /&gt;else casecontrol=0;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%LET agerange = 5;&amp;nbsp;&lt;BR /&gt;%LET ratio = 2;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;DATA cases controls;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;SET population;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;IF casecontrol = 1 THEN OUTPUT cases;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ELSE OUTPUT controls;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC FREQ NOPRINT DATA=cases;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;TABLES age*gender/OUT=caseout;&amp;nbsp;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;%MACRO sample(v_age, v_gender, v_count);&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;DATA qualify1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SET controls;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; WHERE (&amp;amp;v_age-&amp;amp;agerange &amp;lt;= age &amp;lt;= &amp;amp;v_age+&amp;amp;agerange)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; AND&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (gender = "&amp;amp;v_gender");&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;case_age = &amp;amp;v_age;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;case_gender = "&amp;amp;v_gender";&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;SEED = RANUNI(0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;PROC SORT;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; BY SEED;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;DATA qualify2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SET qualify1 NOBS=totobs;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF _N_ &amp;lt;= &amp;amp;v_count*&amp;amp;ratio;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF &amp;amp;v_count*&amp;amp;ratio &amp;lt;= totobs THEN tag = 'yes';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE tag = 'no';&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;PROC APPEND BASE=matches DATA=qualify2 force; /*new data set ‘matches’ will contain the matched controls*/&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;PROC SORT DATA=qualify2 OUT=temp1 (KEEP=uniqueid);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; BY uniqueid;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;PROC SORT DATA=controls OUT=temp2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; BY uniqueid;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;DATA controls;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; MERGE temp1(IN=in1) temp2(IN=in2);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; BY uniqueid;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF in2 AND NOT in1;&lt;BR /&gt;&lt;BR /&gt;%MEND sample;&lt;BR /&gt;&lt;BR /&gt;DATA _NULL_; /*This data step calls the macro.*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp;SET caseout;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CALL EXECUTE ('%sample('||age||','||gender||','||count||')');&lt;BR /&gt;RUN;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;THE ERROR&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;The error I get is the following (which then of course influences everything that follows):&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;P&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;254:30 254:40 254:53&lt;BR /&gt;NOTE: There were 29 observations read from the data set WORK.CASEOUT.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: CALL EXECUTE generated line.&lt;BR /&gt;1 + DATA qualify1; SET controls; WHERE (25-0 &amp;lt;= age &amp;lt;= 25+0) AND (gender&lt;BR /&gt;= "0"); case_age = 25; case_gender = "0"; SEED = RANUNI(0);&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;"25" is simply the youngest age in my data set, which ranges from 25 to 76. I do not understand why it gives the error that "where" needs a compatible variable. Both "age" and "gender" are numeric in my dataset. I double checked to make sure. I am not sure if the "NOTE" above it has somehow converted one of them in a character, and hence the mistake?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;Any help to figure this out would be greatly appreciated.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="gmail_default"&gt;Thank you very much&lt;/DIV&gt;</description>
      <pubDate>Sat, 09 Oct 2021 00:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773174#M245566</guid>
      <dc:creator>Manol_Jovani</dc:creator>
      <dc:date>2021-10-09T00:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773175#M245567</link>
      <description>&lt;P&gt;It's hard to see what's going on as you have posted your code and warnings / errors separately so we don't know where they are happening. Please post your complete SAS log including messages with the SAS statement at the start - OPTIONS MPRINT; - so we can see what the macro is doing.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 01:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773175#M245567</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-10-09T01:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773177#M245569</link>
      <description>Gender is expected to be a character in the code above, not numeric. Age should be numeric. &lt;BR /&gt;&lt;BR /&gt;This tells you have a type issue:&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.</description>
      <pubDate>Sat, 09 Oct 2021 01:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773177#M245569</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-09T01:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773178#M245570</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/172503"&gt;@Manol_Jovani&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Your where clause "&lt;SPAN&gt;WHERE (25-0 &amp;lt;= age &amp;lt;= 25+0) AND (gender&lt;/SPAN&gt;&lt;SPAN&gt;= "0");" is the cause of error.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try changing&amp;nbsp; (25-0 &amp;lt;= age &amp;lt;= 25+0) . I am giving a sample code below using sashelp.class.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In my example age is between 10 and 12. You can replace 10 with 25 and 12 with 76.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set sashelp.class(Rename=(sex=gender));
 where (age between 10 and 12) and (gender="M");
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The message " ERROR: WHERE clause operator requires compatible variables" implies the&amp;nbsp; variables and the values you are comparing with may not be of the same type (for example one may be a numeric and other may be of character&amp;nbsp;types.) Please verify.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 01:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773178#M245570</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-10-09T01:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773181#M245571</link>
      <description>&lt;P&gt;The message is very clear.&lt;/P&gt;
&lt;P&gt;What you say is less clear:&amp;nbsp;How can you say GENDER is numeric, and code GENDER=&lt;SPAN&gt;"0"&amp;nbsp; ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Remove the quotes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 03:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773181#M245571</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-10-09T03:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773210#M245592</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I am not saying that Gender is numeric or character. I tried to clarify what the error message was in my own way.&lt;BR /&gt;Under similar situation, I would find the type of my variables in the where clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 12:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773210#M245592</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-10-09T12:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773229#M245596</link>
      <description>&lt;P&gt;Did you have code that ran correctly before creating the macro? That should be first thing. The data problem you are having should have been identified/ resolved with the non-macro code debugging.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 18:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773229#M245596</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-09T18:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773235#M245601</link>
      <description>Yes, the code above the macro works fine, there is no problem there. Is that what you are asking?&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Oct 2021 20:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773235#M245601</guid>
      <dc:creator>Manol_Jovani</dc:creator>
      <dc:date>2021-10-09T20:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773238#M245603</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;I am not saying that Gender is numeric or character.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Yes you are&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;SPAN&gt;"25" is simply the youngest age in my data set, which ranges from 25 to 76. I do not understand why it gives the error that "where" needs a compatible variable. &lt;FONT color="#FF0000"&gt;Both "age" and "gender" are numeric in my dataset.&lt;/FONT&gt; I double checked to make sure. I am not sure if the "NOTE" above it has somehow converted one of them in a character, and hence the mistake?&lt;/SPAN&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Under similar situation, I would find the type of my variables in the where clause.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I don't know what this means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did removing the quotes fix the error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 22:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773238#M245603</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-10-09T22:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: MATCHING WITH SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773315#M245642</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/172503"&gt;@Manol_Jovani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, the code above the macro works fine, there is no problem there. Is that what you are asking?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. I am asking if the part inside the macro, when tested without any macro coding, ran. The question about whether quotes are needed or not should have been resolved at that time before adding macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Messages about "conversion"&lt;/P&gt;
&lt;PRE&gt;Numeric values have been converted to character values at the places given by:
(Line):(Column).&lt;/PRE&gt;
&lt;P&gt;is a warning that &lt;STRONG&gt;you&lt;/STRONG&gt; are writing code incorrectly. That message says that you are doing something that treats a numeric variable as character. You may not know this yet, but numeric variables when converted to character typically do not create a value that works as you may expect.&lt;/P&gt;
&lt;P&gt;Here is a very simple example of the incompatible "where" clause.&lt;/P&gt;
&lt;PRE&gt;data example;;
  /* character value with digits*/
  x='123';
  /* numeric value*/
  y=123;

run;

data result;
  set example;
  where x=y;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Caution:&lt;/STRONG&gt;&amp;nbsp; Writing macros without RUN statements ending Procedures or Data steps is also a "gotcha" just waiting to happen.&lt;/P&gt;
&lt;P&gt;You can write macro code quite easily that incorrectly by-passes an "implied" run and have lines from a following procedure or data step thought as part of the current one running. This is extremely easy if one macro calls another. You can spend a LOT of time tracing down such odd seeming problems caused by this small bit. Ask me how I know&lt;span class="lia-unicode-emoji" title=":downcast_face_with_sweat:"&gt;😓&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is why code you attempt to create inside a macro has to be made without macros and run correctly before ever adding a %macro/ %mend. around it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 06:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MATCHING-WITH-SAS/m-p/773315#M245642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-11T06:00:37Z</dc:date>
    </item>
  </channel>
</rss>

