<?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: How to combine PROC SQL statement in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422240#M2167</link>
    <description>&lt;P&gt;A good start to learning would be to learn the language itself - this is Base SAS.&amp;nbsp; SQL can be used in a procedure, however it really only has usefulness if you are a) connecting to a database, or b) have some specific join.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, starting with macro and macro variables will not teach you anything other than bad coding techniques.&lt;/P&gt;
&lt;P&gt;Thirdly, code formatting is&amp;nbsp;&lt;STRONG&gt;far more&lt;/STRONG&gt; important than what the code does.&amp;nbsp; If a user can't read it then its useless.&lt;/P&gt;
&lt;P&gt;I would also avoid named literals as much as possible - this being the "..."n.&amp;nbsp; They are only useful if the database has names which are not SAS compliant, all other times use SAS specific.&lt;/P&gt;
&lt;P&gt;Now your code can be written as:&lt;/P&gt;
&lt;PRE&gt;data med1516 (keep=year dob medication treatment sex id startdate enddate amtdaysonmed);
  set drugdata.year1516 in=a 
      drugdata.year1516 in=b
  where medication=1;
  if a then year=.;
  else amtdaysonmed=enddate-startdate;
run;&lt;/PRE&gt;
&lt;P&gt;For point 2, variables are created on the output data, so cannot be used in the current code, unless you use the keyword computed.&lt;/P&gt;
&lt;P&gt;For point 3, yes, use proc sort, or if you have to use SQL, order by.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2017 10:35:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-12-19T10:35:05Z</dc:date>
    <item>
      <title>How to combine PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422234#M2166</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to SAS .&amp;nbsp;Looking to see the number of patients that have taken a&amp;nbsp;medication only once for between 1-5 days and for what treatment and compare it with the 1995/96 data. The script below is for 2015/16 data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%_eg_conditional_dropds(WORK."%STR(1516)"n);&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.'1516'n AS&lt;BR /&gt;SELECT t1.FYEAR,&lt;BR /&gt;t1.DOB,&lt;BR /&gt;t1.MEDICATION,&lt;BR /&gt;t1.TREATMENT&lt;BR /&gt;t1.SEX,&lt;BR /&gt;t1.ID,&lt;BR /&gt;t1.STARTDATE,&lt;BR /&gt;t1.ENDDATE&lt;BR /&gt;&lt;BR /&gt;FROM DRUGDATA.YEAR1516 t1 where MEDICATION=1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;create table &lt;STRONG&gt;MED1516&lt;/STRONG&gt;&lt;BR /&gt;as select t1.DOB,&lt;BR /&gt;t1.MEDICATION,&lt;BR /&gt;t1.TREATMENT&lt;BR /&gt;t1.SEX,&lt;BR /&gt;t1.ID,&lt;BR /&gt;t1.STARTDATE,&lt;BR /&gt;t1.ENDDATE,&lt;BR /&gt;ENDDATE-STARTDATE AS amtdaysonmed&lt;BR /&gt;&lt;BR /&gt;FROM DRUGDATA.YEAR1516 t1 where MEDICATION=1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have three questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Is there a way to combine the two steps and still create MED1516?.&lt;BR /&gt;2. When I tried to add amtdaysonmed &amp;lt;6 (FROM DRUGDATA.YEAR1516 t1 where MEDICATION=1 and amtdaysonmed &amp;lt;6) it said it couldn't find amtdaysonmed. &lt;STRONG&gt;&lt;EM&gt;ERROR: The following columns were not found in the contributing tables: amtdaysonmed.&lt;/EM&gt;&lt;/STRONG&gt; But I can see&amp;nbsp;&lt;SPAN&gt;amtdaysonmed when I checked on output Data.&lt;/SPAN&gt;I have tried to do another PROC SQL and add amtdaysonmed but it doesn't work either&lt;/P&gt;&lt;P&gt;3. Is there a way to sort the data by the treatments the drugs are used for?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you for your time&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 09:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422234#M2166</guid>
      <dc:creator>learn2learn</dc:creator>
      <dc:date>2017-12-19T09:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422240#M2167</link>
      <description>&lt;P&gt;A good start to learning would be to learn the language itself - this is Base SAS.&amp;nbsp; SQL can be used in a procedure, however it really only has usefulness if you are a) connecting to a database, or b) have some specific join.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, starting with macro and macro variables will not teach you anything other than bad coding techniques.&lt;/P&gt;
&lt;P&gt;Thirdly, code formatting is&amp;nbsp;&lt;STRONG&gt;far more&lt;/STRONG&gt; important than what the code does.&amp;nbsp; If a user can't read it then its useless.&lt;/P&gt;
&lt;P&gt;I would also avoid named literals as much as possible - this being the "..."n.&amp;nbsp; They are only useful if the database has names which are not SAS compliant, all other times use SAS specific.&lt;/P&gt;
&lt;P&gt;Now your code can be written as:&lt;/P&gt;
&lt;PRE&gt;data med1516 (keep=year dob medication treatment sex id startdate enddate amtdaysonmed);
  set drugdata.year1516 in=a 
      drugdata.year1516 in=b
  where medication=1;
  if a then year=.;
  else amtdaysonmed=enddate-startdate;
run;&lt;/PRE&gt;
&lt;P&gt;For point 2, variables are created on the output data, so cannot be used in the current code, unless you use the keyword computed.&lt;/P&gt;
&lt;P&gt;For point 3, yes, use proc sort, or if you have to use SQL, order by.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 10:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422240#M2167</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-19T10:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine PROC SQL statement</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422316#M2168</link>
      <description>&lt;P&gt;Thank you. I am looking at some of the available information online to learn. I am using SAS EG so the output was based on the code suggested from doing it manually. I have some experience working with Stata which seems similar so will try to learn the language instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your time&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 15:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-combine-PROC-SQL-statement/m-p/422316#M2168</guid>
      <dc:creator>learn2learn</dc:creator>
      <dc:date>2017-12-19T15:33:08Z</dc:date>
    </item>
  </channel>
</rss>

