<?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: select into doesn't work in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5572#M2245</link>
    <description>Thanks to all. Now it works. I just was not careful.</description>
    <pubDate>Tue, 20 Nov 2007 14:31:11 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-11-20T14:31:11Z</dc:date>
    <item>
      <title>select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5563#M2236</link>
      <description>Hi gyes.&lt;BR /&gt;
&lt;BR /&gt;
Can you please, say me what is wrong in this code:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;libname test "C:\Temp";&lt;BR /&gt;
&lt;BR /&gt;
%macro checkfk(pkTab, pk, fkTab, fk, out=results, print=no);&lt;BR /&gt;
       %let tmp='';&lt;BR /&gt;
       proc sql;&lt;BR /&gt;
            select name into :tmp separated by ' ' from TRIM("test."||&amp;amp;fkTab)&lt;BR /&gt;
                               where TRIM("test."||&amp;amp;fk) in (TRIM("test."||&amp;amp;pk));&lt;BR /&gt;
       quit;&lt;BR /&gt;
%mend checkfk;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%checkfk(pkTab=Sex, pk=Names.sex_id, fkTab=Names, fk=Sex.sex_id, out=results, print=yes); &lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Here is the log:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;293   libname test "C:\Temp";&lt;BR /&gt;
NOTE: Libref TEST was successfully assigned as follows:&lt;BR /&gt;
     Engine:        V9&lt;BR /&gt;
     Physical Name: C:\Temp&lt;BR /&gt;
294&lt;BR /&gt;
295   %macro checkfk(pkTab, pk, fkTab, fk, out=results, print=no);&lt;BR /&gt;
296       %let tmp='';&lt;BR /&gt;
297       proc sql;&lt;BR /&gt;
298            select name into :tmp separated by ' ' from TRIM("test."||&amp;amp;fkTab)&lt;BR /&gt;
299                   where TRIM("test."||&amp;amp;fk) in (TRIM("test."||&amp;amp;pk));&lt;BR /&gt;
300       quit;&lt;BR /&gt;
301   %mend checkfk;&lt;BR /&gt;
302&lt;BR /&gt;
303&lt;BR /&gt;
304   %checkfk(pkTab=Sex, pk=Names.sex_id, fkTab=Names, fk=Sex.sex_id, out=results, print=yes);&lt;BR /&gt;
NOTE: Line generated by the invoked macro "CHECKFK".&lt;BR /&gt;
1               select name into :tmp separated by ' ' from TRIM("test."||&amp;amp;fkTab)&lt;BR /&gt;
1   !                where TRIM("test."||&amp;amp;fk) in (TRIM("test."||&amp;amp;pk));     quit;&lt;BR /&gt;
                                                     ----&lt;BR /&gt;
                                                     79&lt;BR /&gt;
                                                     76&lt;BR /&gt;
ERROR 79-322: Expecting a SELECT.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&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;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
There are 2 tables:&lt;BR /&gt;
Table &lt;I&gt;Names&lt;/I&gt; with 3 columns &lt;I&gt;name_id, name, sex_id&lt;/I&gt;&lt;BR /&gt;
Table &lt;I&gt;Sex&lt;/I&gt; with 2 columns &lt;I&gt;sex_id, sex&lt;/I&gt;</description>
      <pubDate>Fri, 16 Nov 2007 11:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5563#M2236</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-16T11:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5564#M2237</link>
      <description>I don't really follow what is going on here.&lt;BR /&gt;
&lt;BR /&gt;
The trim() function doesn't belong, the SQL processor won't recognise its function.&lt;BR /&gt;
&lt;BR /&gt;
If you want to create a name by concatenating a string to a macro value, you won't need double quotes unless it is a value being inserted into a variable.&lt;BR /&gt;
&lt;BR /&gt;
The syntax breaks the Zender rule 1 of macro creation by not starting with valid SAS code.  PK might eventually resolve to something like TEST.SEX.SEXID which as a three level name is valid for a catalog entry, but not for a table or  column.  The same issue exists with your use of PK.&lt;BR /&gt;
&lt;BR /&gt;
So, create valid SQL code without any macro symbols and then gradually replace them one by one.&lt;BR /&gt;
&lt;BR /&gt;
I hope that your source table will have column names in it as Dictionary.Columns has or this will break again.&lt;BR /&gt;
&lt;BR /&gt;
Kind regards&lt;BR /&gt;
&lt;BR /&gt;
David</description>
      <pubDate>Fri, 16 Nov 2007 23:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5564#M2237</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-16T23:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5565#M2238</link>
      <description>David -- thanks, you're so kind to give me my own rule. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; I admit, I am rather opinionated about the "starting with working SAS code" rule. However, based on "mumble-ty mumble" years of SAS and Macro programming, the rule has NEVER failed to produce good results.&lt;BR /&gt;
 &lt;BR /&gt;
Ihor -- This is not an ODS or BASE Reporting procedure (PRINT, REPORT, TABULATE) question. And I was going to suggest that you contact Tech Support for help. But I was also going to suggest what David has already suggested: start with a working SAS program. Before you contact Tech Support with a macro program problem, you owe it to yourself to be able to produce a working SAS program that is the equivalent of the code you want to generate. I cannot stress this too much. The SAS Macro facility is like a BIG typewriter -- the only purpose of the SAS Macro facility is to make your life easy by generating code for you as an alternative to you typing code.&lt;BR /&gt;
      &lt;BR /&gt;
  Your best bet for help with Macro questions is to read the SAS Macro facility documentation -- and not just to read it searching for one idea, but to really study it and run some of the examples and try to understand what's happening with the macro code. Or to search on Google or support.sas.com for papers or samples that are relevant or to contact Tech Support. Some relevant papers from a quick Google search are:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi27/p071-27.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi27/p071-27.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.ats.ucla.edu/stat/sas/library/nesug98/p193.pdf" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/library/nesug98/p193.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.ats.ucla.edu/STAT/sas/library/nesug99/cc107.pdf" target="_blank"&gt;http://www.ats.ucla.edu/STAT/sas/library/nesug99/cc107.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
You really will NOT be sorry if you start with a WORKING program first.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 17 Nov 2007 02:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5565#M2238</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-17T02:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5566#M2239</link>
      <description>Sorry gyes, but I still cannot understand why it doesn't work:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
%let numrows=0;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
       select count(name_id) into :numrows from test.Names&lt;BR /&gt;
               where test.Sex.sex_id = test.Names.sex_id;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
It says that syntax error.</description>
      <pubDate>Mon, 19 Nov 2007 12:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5566#M2239</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-19T12:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5567#M2240</link>
      <description>Your query is referring to columns from two different tables, but your from statement only defines one table...&lt;BR /&gt;
&lt;BR /&gt;
I believe it should be something like:&lt;BR /&gt;
%let numrows=0;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select count(name_id) into :numrows &lt;BR /&gt;
from test.Names,test.Sex&lt;BR /&gt;
where test.Sex.sex_id = test.Names.sex_id;&lt;BR /&gt;
quit;</description>
      <pubDate>Mon, 19 Nov 2007 14:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5567#M2240</guid>
      <dc:creator>advoss</dc:creator>
      <dc:date>2007-11-19T14:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5568#M2241</link>
      <description>Hi:&lt;BR /&gt;
  SAS usually gives me an error message if I have a 3 level name:&lt;BR /&gt;
test.sex.sex_id or test.names.sex_id&lt;BR /&gt;
  &lt;BR /&gt;
  Generally, I need to do this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
from test.Names as a, test.Sex as b&lt;BR /&gt;
where a.sex_id = b.sex_id&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
However, the other issue I see is that the working SQL shown does not match, at all, the SQL (with the separated by) inside the first macro program. So there is still a disconnect between what has just been posted and the original macro program.&lt;BR /&gt;
 &lt;BR /&gt;
I still maintain that Ihor's best bet for help is to contact Tech Support, especially since this is the forum for ODS and Base SAS Reporting procedures (PRINT, REPORT, TABULATE) and NOT SAS PROC SQL or SAS Macro.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 19 Nov 2007 14:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5568#M2241</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-19T14:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5569#M2242</link>
      <description>Yes, thanks, but it still doesn't work. Syntax error again.</description>
      <pubDate>Mon, 19 Nov 2007 14:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5569#M2242</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-19T14:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5570#M2243</link>
      <description>Ihor:&lt;BR /&gt;
  This is the point at which you really need to contact Tech Support. To find out how to open a track with Tech Support, go to: &lt;A href="http://support.sas.com" target="_blank"&gt;http://support.sas.com&lt;/A&gt; and on the left-hand navigation area, click on the link entitled "Submit a Problem".&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 19 Nov 2007 15:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5570#M2243</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-19T15:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5571#M2244</link>
      <description>Yes, Cynthia is correct (as usual).  You need to provide aliases rather than work with three part names.</description>
      <pubDate>Mon, 19 Nov 2007 15:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5571#M2244</guid>
      <dc:creator>advoss</dc:creator>
      <dc:date>2007-11-19T15:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: select into doesn't work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5572#M2245</link>
      <description>Thanks to all. Now it works. I just was not careful.</description>
      <pubDate>Tue, 20 Nov 2007 14:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/select-into-doesn-t-work/m-p/5572#M2245</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-20T14:31:11Z</dc:date>
    </item>
  </channel>
</rss>

