<?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: sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26839#M6166</link>
    <description>Hi SPR,&lt;BR /&gt;
&lt;BR /&gt;
As you mentioned i removed the quotes from the macro varible and tried with this data step;&lt;BR /&gt;
&lt;BR /&gt;
data ageGE7NY ageGE7NJ;&lt;BR /&gt;
set agege7;&lt;BR /&gt;
IF COMPNO = &amp;amp;NYcomplist. then output ageGE7NY;&lt;BR /&gt;
else&lt;BR /&gt;
IF COMPNO = &amp;amp;NJcomplist. then output ageGE7NJ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
but still am getting an error.</description>
    <pubDate>Thu, 10 Mar 2011 17:33:56 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-03-10T17:33:56Z</dc:date>
    <item>
      <title>sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26831#M6158</link>
      <description>Hi ,&lt;BR /&gt;
 &lt;BR /&gt;
I have created a table with AGEge7 and need to get seperate compno output for &amp;amp;NY and &amp;amp;NJ. So i tried with below code&lt;BR /&gt;
/*Table WORK.AGEGE7 created, with 477 rows and 2 columns.*/&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
      create table ageGE7 as&lt;BR /&gt;
      select var1,age from outf &lt;BR /&gt;
           where age &amp;gt; 7 ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/*Table WORK.AGEGE7 created, with 410 rows and 2 columns.*/&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
      create table ageGE7NY as&lt;BR /&gt;
      select Var1,age from outf &lt;BR /&gt;
           where age &amp;gt; 7 and compno in (&amp;amp;NY);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/*Table WORK.AGEGE7 created, with 67 rows and 2 columns.*/&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
      create table ageGE7NJ as&lt;BR /&gt;
      select var1,age from outf &lt;BR /&gt;
           where age &amp;gt; 7 and compno in (&amp;amp;NJ);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
In Stead of above two steps , i tried to combine in a single step, but am getting an incorrect output..&lt;BR /&gt;
&lt;BR /&gt;
/*NOTE: The data set WORK.AGEGE7NY has 67 observations and 2 variables.*/&lt;BR /&gt;
/*NOTE: The data set WORK.AGEGE7NJ has 67 observations and 2 variables.*/&lt;BR /&gt;
data ageGE7NY ageGE7NJ;&lt;BR /&gt;
SET ageGE7;&lt;BR /&gt;
IF compno in "&amp;amp;NY" then output ageGE7NY;&lt;BR /&gt;
else &lt;BR /&gt;
IF compno in "&amp;amp;NJ" then output ageGE7NJ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks in Advance.</description>
      <pubDate>Thu, 10 Mar 2011 16:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26831#M6158</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-10T16:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26832#M6159</link>
      <description>Check your SAS code - it's clear that the different approaches are also using different SAS input files.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 10 Mar 2011 16:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26832#M6159</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-03-10T16:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26833#M6160</link>
      <description>Two things I need to know to help.  First what do you have in the NY and NJ macro variables?  Two, how is the last datastep actually written, because those "IN" statements are not valid in a DATA step.  Should the quotes in those statements actually be parentheses?

Message was edited by: Curtis Mack</description>
      <pubDate>Thu, 10 Mar 2011 16:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26833#M6160</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2011-03-10T16:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26834#M6161</link>
      <description>Helping the OP diagnose this particular SAS exercise is a guessing-game, what without the exact (COPY/PASTE) SAS-generated log being posted.  I agree with the prior REPLY in that the use of "IN" in the IF/THEN construct does require surrounding parentheses, so the DATA step code as illustrated will not execute successfully.  &lt;BR /&gt;
&lt;BR /&gt;
Suggest some additional self-initiated desk-checking (given prior post replies), then if still unresolved re-post a reply with the SASLOG output (using COPY/PASTE) with call code revealed.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 10 Mar 2011 17:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26834#M6161</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-03-10T17:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26835#M6162</link>
      <description>Hi Mack,&lt;BR /&gt;
&lt;BR /&gt;
For NY macro variables - having values (03,34,20,31) and NJ (01,11). &lt;BR /&gt;
Instead of data step can we write proc sql , so we can get exact output.&lt;BR /&gt;
&lt;BR /&gt;
Please let me know .&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 10 Mar 2011 17:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26835#M6162</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-10T17:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26836#M6163</link>
      <description>Hello Ravenaat,&lt;BR /&gt;
&lt;BR /&gt;
Look at your ifs in the last datastep:&lt;BR /&gt;
&lt;BR /&gt;
IF compno in "&amp;amp;NY" then output ageGE7NY&lt;BR /&gt;
&lt;BR /&gt;
should be&lt;BR /&gt;
&lt;BR /&gt;
IF compno in &amp;amp;NY then output ageGE7NY&lt;BR /&gt;
&lt;BR /&gt;
If you replace &amp;amp;NY by (03,34,20,31) in your code you get in  "(03,34,20,31)" which is obvious error.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Thu, 10 Mar 2011 17:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26836#M6163</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-10T17:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26837#M6164</link>
      <description>SPR said what I would have said</description>
      <pubDate>Thu, 10 Mar 2011 17:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26837#M6164</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2011-03-10T17:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26838#M6165</link>
      <description>Not exactly!</description>
      <pubDate>Thu, 10 Mar 2011 17:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26838#M6165</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-10T17:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26839#M6166</link>
      <description>Hi SPR,&lt;BR /&gt;
&lt;BR /&gt;
As you mentioned i removed the quotes from the macro varible and tried with this data step;&lt;BR /&gt;
&lt;BR /&gt;
data ageGE7NY ageGE7NJ;&lt;BR /&gt;
set agege7;&lt;BR /&gt;
IF COMPNO = &amp;amp;NYcomplist. then output ageGE7NY;&lt;BR /&gt;
else&lt;BR /&gt;
IF COMPNO = &amp;amp;NJcomplist. then output ageGE7NJ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
but still am getting an error.</description>
      <pubDate>Thu, 10 Mar 2011 17:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26839#M6166</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-10T17:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26840#M6167</link>
      <description>You need to look at your code the ='s should be IN's&lt;BR /&gt;
&lt;BR /&gt;
data ageGE7NY ageGE7NJ;&lt;BR /&gt;
set agege7;&lt;BR /&gt;
IF COMPNO in &amp;amp;NYcomplist. then output ageGE7NY;&lt;BR /&gt;
else&lt;BR /&gt;
IF COMPNO in &amp;amp;NJcomplist. then output ageGE7NJ;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 10 Mar 2011 17:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26840#M6167</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2011-03-10T17:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26841#M6168</link>
      <description>Mack , you mentioned the "IN" statements are not valid in a DATA step.</description>
      <pubDate>Thu, 10 Mar 2011 17:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26841#M6168</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-10T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26842#M6169</link>
      <description>I said "&lt;U&gt;those&lt;/U&gt; "IN" statements are not valid " meaning the way they were written, not IN statements in general.  Sorry, I could have been clearer.</description>
      <pubDate>Thu, 10 Mar 2011 17:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26842#M6169</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2011-03-10T17:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26843#M6170</link>
      <description>Hi:&lt;BR /&gt;
   As you can see, the IN is valid in an IF statement and in a WHERE statement in a DATA step program. Before you use macro variables, it is useful to have a -working- program to start with, so you know the correct syntax needed. (But note that my IN condition does NOT use quoted strings because AGE is a numeric variable. It would be WRONG to use IN with quoted strings for a numeric variable. And your originally posted code showed quotes around your macro variable -- which was an incorrect usage of IN -- since the IN conditions go inside parentheses.)&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
977  data one;&lt;BR /&gt;
978    set sashelp.class;&lt;BR /&gt;
979    if age in (11, 12, 13) then output;&lt;BR /&gt;
980  run;&lt;BR /&gt;
                          &lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.ONE has 10 observations and 5 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.06 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
             &lt;BR /&gt;
                         &lt;BR /&gt;
981&lt;BR /&gt;
982  data two;&lt;BR /&gt;
983    set sashelp.class;&lt;BR /&gt;
984    where age in (11, 12, 13);&lt;BR /&gt;
985  run;&lt;BR /&gt;
                        &lt;BR /&gt;
NOTE: There were 10 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
      WHERE age in (11, 12, 13);&lt;BR /&gt;
NOTE: The data set WORK.TWO has 10 observations and 5 variables.&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;BR /&gt;
                 &lt;BR /&gt;
                       &lt;BR /&gt;
986&lt;BR /&gt;
987  data three four five;&lt;BR /&gt;
988    set sashelp.class;&lt;BR /&gt;
989    if age in (11, 12, 13) then output three;&lt;BR /&gt;
990    else if age in (14, 15) then output four;&lt;BR /&gt;
991    else output five;&lt;BR /&gt;
992  run;&lt;BR /&gt;
                   &lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.THREE has 10 observations and 5 variables.&lt;BR /&gt;
NOTE: The data set WORK.FOUR has 8 observations and 5 variables.&lt;BR /&gt;
NOTE: The data set WORK.FIVE has 1 observations and 5 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.07 seconds&lt;BR /&gt;
      cpu time            0.04 seconds&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 10 Mar 2011 17:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26843#M6170</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-03-10T17:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26844#M6171</link>
      <description>Thanks for all !!!</description>
      <pubDate>Thu, 10 Mar 2011 17:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql/m-p/26844#M6171</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-10T17:52:37Z</dc:date>
    </item>
  </channel>
</rss>

