<?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: Proc sql: new table where patient had ≥2 visits in either column? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748209#M234968</link>
    <description>&lt;P&gt;Columns names with nonalphanum characters must be specified as &lt;EM&gt;name literals&lt;/EM&gt;, i.e. quoted string followed by the letter n :&amp;nbsp; 'visits16.pcp'n . Name literals can be used anywhere a column name is required.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jun 2021 19:30:17 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2021-06-15T19:30:17Z</dc:date>
    <item>
      <title>Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748195#M234958</link>
      <description>&lt;P&gt;I have a dataset called records where each row is an individual patient (no duplicates) and I have a column for number of patient visits during 2015 and a column for number of patient visits during 2016.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new table that only contains patients who had 2 or more (≥2) patient visits during 2015 and/or during 2016.&lt;/P&gt;&lt;P&gt;e.g. include patients who had either:&lt;/P&gt;&lt;P&gt;1. ≥2 visits during 2015 and 0 visits during 2016&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;2. 0 visits during 2015 and ≥ 2 visits during 2016&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;3. 1 visit during 2015 and 1 visit during 2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code has to be incorrect:&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;create&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;table&lt;/SPAN&gt; records_15_16&amp;nbsp;&lt;SPAN class="s2"&gt;as&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;select&lt;SPAN class="s1"&gt; *&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;from&lt;SPAN class="s1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;records&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;WHERE&lt;/SPAN&gt; (visits15 &amp;gt;= 2 AND visits16 = 0) OR&amp;nbsp;(visits15 = 0 AND visits16 &amp;gt;=2)&amp;nbsp;OR&amp;nbsp;(visits15 = 1 AND visits16 = 1) ;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s4"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 18:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748195#M234958</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-06-15T18:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748200#M234961</link>
      <description>&lt;P&gt;Why do you say it's incorrect? Was the output you got not what you were expecting?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 18:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748200#M234961</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-15T18:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748201#M234962</link>
      <description>&lt;P&gt;or would this work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#003399"&gt;proc sql;&lt;BR /&gt;create table records_15_16 AS&lt;BR /&gt;select *, visits15 + visits16 AS total&lt;BR /&gt;from records&lt;BR /&gt;&lt;EM&gt;where&lt;/EM&gt; &lt;STRONG&gt;calculated&lt;/STRONG&gt; total &amp;gt;=2;&lt;BR /&gt;quit; &lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 18:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748201#M234962</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-06-15T18:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748204#M234964</link>
      <description>&lt;P&gt;Well my column names are spelled visits15.pcp and visits16.pcp and SAS gives a syntax error for the period in the column name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 19:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748204#M234964</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-06-15T19:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748205#M234965</link>
      <description>&lt;P&gt;If it was me, I would run the query and then open the dataset and check it out or use proc print and print for the 3 cases you mentioned above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the period in column name is an issue, then you might have to rename it.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 19:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748205#M234965</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-15T19:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748209#M234968</link>
      <description>&lt;P&gt;Columns names with nonalphanum characters must be specified as &lt;EM&gt;name literals&lt;/EM&gt;, i.e. quoted string followed by the letter n :&amp;nbsp; 'visits16.pcp'n . Name literals can be used anywhere a column name is required.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 19:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748209#M234968</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-06-15T19:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748212#M234970</link>
      <description>&lt;P&gt;Well, using the rename option is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp; records&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;rename&lt;/SPAN&gt;=(visits15.pcp=visits15&amp;nbsp; visits16.pcp=visits16));&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt;&amp;nbsp;records_2 ;&lt;/P&gt;&lt;P class="p2"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;SPAN class="s3"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;datasets&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;contents&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;data&lt;/SPAN&gt;=records_2&amp;nbsp; &amp;nbsp;&lt;SPAN class="s2"&gt;order&lt;/SPAN&gt;=collate;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#993366"&gt;Variable name visits15.pcp is not valid.&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT color="#993366"&gt;ERROR: Invalid value for the RENAME option.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 19:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748212#M234970</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-06-15T19:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748214#M234972</link>
      <description>Can you get rid of the dot? It probably thinks there is a library called visits15?</description>
      <pubDate>Tue, 15 Jun 2021 19:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748214#M234972</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-15T19:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: new table where patient had ≥2 visits in either column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748215#M234973</link>
      <description>&lt;P&gt;Okay, ignore the syntax error. I was reading off the column name from Excel and I overlooked that SAS automatically changed visits15.pcp to visits15_pcp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I corrected my code as shown in &lt;FONT color="#FF0000"&gt;red&lt;/FONT&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;SQL&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;create&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;table&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;records_15_16&amp;nbsp;&lt;SPAN class="s2"&gt;as&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;select&lt;SPAN class="s1"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;*&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;from&lt;SPAN class="s1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;records&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(visits15_pcp &amp;gt;= 2 AND visits16_pcp = 0) OR&amp;nbsp;(visits15_pcp = 0 AND visits16_pcp &amp;gt;=2)&amp;nbsp;OR&amp;nbsp;(visits15_pcp&amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;gt;=&lt;/FONT&gt; 1 AND visits16_pcp&amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;gt;=&lt;/FONT&gt; 1) ;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s4"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;and the proc sql command above gives the same output as the proc sql below:&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#003399"&gt;proc sql;&lt;BR /&gt;create table records_15_16 AS&lt;BR /&gt;select *, visits15_pcp + visits16_pcp AS total&lt;BR /&gt;from records&lt;BR /&gt;&lt;EM&gt;where&lt;/EM&gt; &lt;STRONG&gt;calculated&lt;/STRONG&gt; total &amp;gt;=2;&lt;BR /&gt;quit;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 19:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-new-table-where-patient-had-2-visits-in-either-column/m-p/748215#M234973</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-06-15T19:56:17Z</dc:date>
    </item>
  </channel>
</rss>

