<?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: Multiple variables for same condition PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386977#M277269</link>
    <description>&lt;P&gt;Excellent, it worked, thank you. Next question, the table it created MOM_2 has multiple columns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DIABETES_1_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIABETES_1_2...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIABETES_2_1...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I collapse the columns so that if the mom has diabetes in any of the diagnosis slots, in any of the visits, then she has diabetes (1=yes) . Basically I want to collapse all the columns I just created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2017 13:07:25 GMT</pubDate>
    <dc:creator>eabc0351</dc:creator>
    <dc:date>2017-08-10T13:07:25Z</dc:date>
    <item>
      <title>Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386848#M277266</link>
      <description>&lt;P&gt;Hello, I have a large healthcare administrative dataset and have multiple variables that will use the same condition. Previously, I used the following code to create a variable for diabetes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;&amp;nbsp;CREATE TABLE&amp;nbsp;MOM_2 AS&lt;BR /&gt;&amp;nbsp;SELECT *, CASE WHEN&lt;BR /&gt;&amp;nbsp;MOM_ID IN (SELECT&amp;nbsp;MOM_ID FROM&amp;nbsp;MOM_1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;WHERE COMPRESS (DX_CODE) BETWEEN "XX.XX" AND "XX.XX")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;THEN 1&lt;BR /&gt;&amp;nbsp;ELSE 0&lt;BR /&gt;&amp;nbsp;END AS&amp;nbsp;DIABETES&lt;BR /&gt;&amp;nbsp;FROM MOM_1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I have multiple&amp;nbsp; DX_CODE variables associated with multiple visits. Example:&lt;/P&gt;&lt;P&gt;DX_CODE1_VISIT1&lt;/P&gt;&lt;P&gt;DX_CODE1_VISIT2&lt;/P&gt;&lt;P&gt;DX_CODE2_VISIT1&lt;/P&gt;&lt;P&gt;DX_CODE2_VISIT2&lt;/P&gt;&lt;P&gt;DX_CODE3_VISIT1&lt;/P&gt;&lt;P&gt;DX_CODE3_VISIT2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My previous PROC SQL statement is not working when I include multiple variables in the WHERE statement. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;&amp;nbsp;CREATE TABLE&amp;nbsp;MOM_1 AS&lt;BR /&gt;&amp;nbsp;SELECT *, CASE WHEN&lt;BR /&gt;&amp;nbsp;MOM_ID IN (SELECT&amp;nbsp;MOM_ID FROM&amp;nbsp;VISIT1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;WHERE COMPRESS (DX_CODE1_VISIT1, DX_CODE2_VISIT1, DX_CODE1_VISIT2, DX_CODE2_VISIT1.....and so on&amp;nbsp;) BETWEEN "XX.XX" AND "XX.XX")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;THEN 1&lt;BR /&gt;&amp;nbsp;ELSE 0&lt;BR /&gt;&amp;nbsp;END AS&amp;nbsp;DIABETES&lt;BR /&gt;&amp;nbsp;FROM MOM_2;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to write multiple variables in the statement?&lt;/P&gt;&lt;P&gt;If so, is it possible to put a range for the DX_CODE variables, rather than writing them each separately (to save time)?. For example:&lt;/P&gt;&lt;P&gt;DX_CODE1_VISIT1-DX_CODE1_VISIT10, DX_CODE2_VISIT1-DX_CODE2_VISIT10...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If including multple variables is not possible, any suggestions?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 00:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386848#M277266</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2017-08-10T00:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386854#M277267</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can go all macro on it, here is a sketch:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro t;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;CREATE TABLE&amp;nbsp;MOM_2 AS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;SELECT *&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%do i=1 %to 3;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;%do j=1 %to 4;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;,CASE WHEN&lt;BR /&gt;&amp;nbsp;MOM_ID IN (SELECT&amp;nbsp;MOM_ID FROM&amp;nbsp;MOM_1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;WHERE COMPRESS (DX_CODE&amp;amp;i._visit&amp;amp;j.) BETWEEN "XX.XX" AND "XX.XX")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;THEN 1&lt;BR /&gt;&amp;nbsp;ELSE 0&lt;BR /&gt;&amp;nbsp;END AS&amp;nbsp;DIABETES_&amp;amp;i._&amp;amp;j.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;%end;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;END AS&amp;nbsp;DIABETES&lt;BR /&gt;&amp;nbsp;FROM MOM_1;&lt;BR /&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%mend t;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%t;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 02:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386854#M277267</guid>
      <dc:creator>OnSAS</dc:creator>
      <dc:date>2017-08-10T02:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386891#M277268</link>
      <description>&lt;P&gt;Yes, the problem here is your fighting SQL. &amp;nbsp;SQL is a language developed to work with normalised data, i.e. data going down a table rather than across. &amp;nbsp;Its really not suited to using data which is transposed in nature - going across the dataset. &amp;nbsp;Now in Base SAS you have constructs to work with this type of data, however its still not optimal. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have two options - and as you have not provided any&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;Test data in the form of a datastep in the body of the post!!&lt;/STRONG&gt;&lt;/U&gt; - I can't go further into other than this:&lt;/P&gt;
&lt;P&gt;1) Still using SQL, then normalise the DX_CODE list so that visit is a separate variable that goes down th etable like:&lt;/P&gt;
&lt;P&gt;VISIT DX_CODE&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XYZ&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;This is how you should model your data if you want to use SQL (and note, if this is Healthcare, then why are you not using CDISC models anyways?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Drop SQL, and goto datastep, something like:&lt;/P&gt;
&lt;PRE&gt;data...;
  set mom_1;
  array dx_code{6};
  if visit=1 then x=1;
  if visit=2 then x=3;
  else x=5;
  if dx_code=dx_code{x} or dx_code=dx_code{x+1} then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386891#M277268</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-10T08:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386977#M277269</link>
      <description>&lt;P&gt;Excellent, it worked, thank you. Next question, the table it created MOM_2 has multiple columns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DIABETES_1_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIABETES_1_2...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DIABETES_2_1...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I collapse the columns so that if the mom has diabetes in any of the diagnosis slots, in any of the visits, then she has diabetes (1=yes) . Basically I want to collapse all the columns I just created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/386977#M277269</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2017-08-10T13:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387137#M277270</link>
      <description>&lt;P&gt;Here, I think you are clearly better of using a data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the data step you can create a new variable that takes the min of all the ones you've created. For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IndDiab = min (of &lt;SPAN&gt;DIABETES_1_1 &amp;nbsp; -- DIABETES_&amp;lt;n&amp;gt;_&amp;lt;m&amp;gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;replace n &amp;amp; m with values&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IndDiab will take 0 when none of the variable in the list is 1.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;good luck.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 18:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387137#M277270</guid>
      <dc:creator>OnSAS</dc:creator>
      <dc:date>2017-08-10T18:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387139#M277271</link>
      <description>&lt;P&gt;Great, thanks so much&amp;nbsp;for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 18:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387139#M277271</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2017-08-10T18:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables for same condition PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387190#M277272</link>
      <description>You are welcome! glad I was able to.</description>
      <pubDate>Thu, 10 Aug 2017 21:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-variables-for-same-condition-PROC-SQL/m-p/387190#M277272</guid>
      <dc:creator>OnSAS</dc:creator>
      <dc:date>2017-08-10T21:15:59Z</dc:date>
    </item>
  </channel>
</rss>

