<?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: Convert to proc sql in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13004#M1479</link>
    <description>Sorry, here is the corrected query.  One line was missing.&lt;BR /&gt;
&lt;BR /&gt;
SELECT A.MRNR, &lt;BR /&gt;
     A.IMMUNE_DATE,  &lt;BR /&gt;
     A.BIRTHDATE,   &lt;BR /&gt;
     A.SEX, &lt;BR /&gt;
     A.Family &amp;amp; (SELECT Count(B.IMMUNE_DATE) &lt;BR /&gt;
FROM ALL_IMMS_POSTSPLIT AS B&lt;BR /&gt;
 WHERE A.MRNR = B.MRNR And A.Family = B.Family And B.IMMUNE_DATE &amp;lt; A.IMMUNE_DATE) +1 AS SequencedName&lt;BR /&gt;
FROM ALL_IMMS_POSTSPLIT AS A&lt;BR /&gt;
ORDER BY A.MRNR, A.Family, A.IMMUNE_DATE;&lt;BR /&gt;
&lt;BR /&gt;
This query works in Access but I'm not sure how to convert it to use in Base SAS.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Paige</description>
    <pubDate>Wed, 06 Oct 2010 23:19:20 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-10-06T23:19:20Z</dc:date>
    <item>
      <title>Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13002#M1477</link>
      <description>What would be the proper way to convert this sql into proc sql in SAS?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SELECT A.MRNR,&lt;BR /&gt;
		A.IMMUNE_DATE,&lt;BR /&gt;
		A.BIRTHDATE, &lt;BR /&gt;
		A.SEX,&lt;BR /&gt;
		A.FAMILY &amp;amp;&lt;BR /&gt;
			(SELECT COUNT(B.IMMUNE_DATE)&lt;BR /&gt;
		FROM ALL_IMMS_POSTSPLIT AS B&lt;BR /&gt;
		WHERE A.MRNR = B.MRNR AND &lt;BR /&gt;
			A.FAMILY = B.FAMILY AND&lt;BR /&gt;
			B.IMMUNE_DATE &amp;lt; A.IMMUNE_DATE) + 1 AS  SEQUENCED_NAME&lt;BR /&gt;
		ORDER BY A.MRNR, A.FAMILY, A.IMMUNE_DATE;&lt;BR /&gt;
&lt;BR /&gt;
Thanks

Message was edited by: egiap14</description>
      <pubDate>Wed, 06 Oct 2010 18:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13002#M1477</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-06T18:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13003#M1478</link>
      <description>The SQL code that you present looks incomplete, and perhaps incorrect.  In particular, the "&amp;amp;" after "a.family" and the lack of a FROM clause where the alias "A" is defined are worrisome.  In general, PROC SQL can handle correlated subqueries (that's the term for the embedded SELECT) without difficulty.</description>
      <pubDate>Wed, 06 Oct 2010 21:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13003#M1478</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-10-06T21:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13004#M1479</link>
      <description>Sorry, here is the corrected query.  One line was missing.&lt;BR /&gt;
&lt;BR /&gt;
SELECT A.MRNR, &lt;BR /&gt;
     A.IMMUNE_DATE,  &lt;BR /&gt;
     A.BIRTHDATE,   &lt;BR /&gt;
     A.SEX, &lt;BR /&gt;
     A.Family &amp;amp; (SELECT Count(B.IMMUNE_DATE) &lt;BR /&gt;
FROM ALL_IMMS_POSTSPLIT AS B&lt;BR /&gt;
 WHERE A.MRNR = B.MRNR And A.Family = B.Family And B.IMMUNE_DATE &amp;lt; A.IMMUNE_DATE) +1 AS SequencedName&lt;BR /&gt;
FROM ALL_IMMS_POSTSPLIT AS A&lt;BR /&gt;
ORDER BY A.MRNR, A.Family, A.IMMUNE_DATE;&lt;BR /&gt;
&lt;BR /&gt;
This query works in Access but I'm not sure how to convert it to use in Base SAS.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Paige</description>
      <pubDate>Wed, 06 Oct 2010 23:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13004#M1479</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-06T23:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13005#M1480</link>
      <description>Hi Paige,&lt;BR /&gt;
&lt;BR /&gt;
In general, you should be able to copy and paste an SQL query from a database into SAS.  This of course assumes the SAS program can access the tables you are referencing (i.e. SAS dataset or via an ACCESS module).  With that said, I think you hit one of the few exceptions where copying charater for character just does not work.  In the example posted, I think the problem is with the "&amp;amp;" after A.family.  In Access, the "&amp;amp;" is used to concatenate two fields together.  However, in SAS the "&amp;amp;" generally signals a macro variable.  To resolve your issue, I would suggest adding a "||" (double pipe) in place of the "&amp;amp;" or you can use one of the built in concatenate functions (cat, catx, etc).  &lt;BR /&gt;
&lt;BR /&gt;
I hope this helps.</description>
      <pubDate>Mon, 11 Oct 2010 04:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13005#M1480</guid>
      <dc:creator>Rambo</dc:creator>
      <dc:date>2010-10-11T04:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13006#M1481</link>
      <description>The error I get now is below.  I tried to use PUT() but then it gives me a syntax error.&lt;BR /&gt;
&lt;BR /&gt;
           PROC SQL;&lt;BR /&gt;
667      CREATE TABLE SEQUENCED AS&lt;BR /&gt;
668      SELECT A.MRNR,&lt;BR /&gt;
669          A.IMMUNE_DATE,&lt;BR /&gt;
670          A.BIRTHDATE,&lt;BR /&gt;
671          A.SEX,&lt;BR /&gt;
672          A.FAMILY || (SELECT COUNT(B.IMMUNE_DATE)&lt;BR /&gt;
673                       FROM ALL_IMMS_POSTSPLIT AS B&lt;BR /&gt;
674                       WHERE A.MRNR = B.MRNR&lt;BR /&gt;
675                              And A.FAMILY = B.FAMILY&lt;BR /&gt;
676                              And B.IMMUNE_DATE &amp;lt; A.IMMUNE_DATE) + 1 AS    SequencedName&lt;BR /&gt;
677      FROM ALL_IMMS_POSTSPLIT AS A&lt;BR /&gt;
678      ORDER BY A.MRNR, A.FAMILY, A.IMMUNE_DATE;&lt;BR /&gt;
&lt;B&gt;ERROR: Concatenation (||) requires character operands.&lt;/B&gt;&lt;BR /&gt;
679  QUIT;&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
680  RUN;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 08 Nov 2010 16:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13006#M1481</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-08T16:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13007#M1482</link>
      <description>Hi Paige,&lt;BR /&gt;
&lt;BR /&gt;
I am not sure how to resolve the new issue.  Looking at the code, it looks like you are adding 1 to the results of the subquery.  I would try to wrap the subquery and the '+1' in parentheses; I am not sure of the order of execution here (i.e. if it concatenates the results and then tries to add 1 to the concatenated string).  &lt;BR /&gt;
&lt;BR /&gt;
Another option to try is to use the left() function.  Since you are converting a number, you will want to have the number left justified.  If not, you may have "blanks" between the value from A.family and the results of the subquery.  Note:  A trim function nested within the left function may also be necessary&lt;BR /&gt;
&lt;BR /&gt;
ex.   left(trim(###)).</description>
      <pubDate>Tue, 16 Nov 2010 23:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13007#M1482</guid>
      <dc:creator>Rambo</dc:creator>
      <dc:date>2010-11-16T23:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to proc sql in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13008#M1483</link>
      <description>You will need to consider using the PUT(&lt;VARNAME&gt;,&lt;FORMAT.&gt;) function to convert the number to a suitable "formatted value" character-string.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/FORMAT.&gt;&lt;/VARNAME&gt;</description>
      <pubDate>Wed, 17 Nov 2010 00:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-proc-sql-in-SAS/m-p/13008#M1483</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-17T00:48:31Z</dc:date>
    </item>
  </channel>
</rss>

