<?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: into statement in proc sql-get error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540694#M149200</link>
    <description>&lt;P&gt;This will not give you your intended result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL NOPRINT;
SELECT DISTINCT EMPID, Ddate    
INTO :E1 - :E&amp;amp;N., :D1 - :D&amp;amp;M.    
FROM RawData;
QUIT; 
%put &amp;amp;E1   ; 
%put &amp;amp;E2   ;
%put &amp;amp;E3   ;
%put &amp;amp;D1   ;
%put &amp;amp;D2   ;
%put &amp;amp;D3   ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See this log snippet:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;68         %put &amp;amp;E1   ;
P01
69         %put &amp;amp;E2   ;
P01
70         %put &amp;amp;E3   ;
P01
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the output of the select is this (if run without noprint):&lt;/P&gt;
&lt;PRE&gt;EMPID  Ddate
------------
P01    1801 
P01    1802 
P01    1803 
P01    1804 
P02    1801 
P02    1802 
P02    1803 
P02    1804 
P03    1801 
P03    1802 
P03    1803 
P03    1804 
&lt;/PRE&gt;
&lt;P&gt;The Ex macro variables catch the &lt;EM&gt;first three&lt;/EM&gt; observations, the Dx the &lt;EM&gt;first four&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;In order to get what you want (my guess), you need to run two separate select into's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct empid
into :e1 - :e&amp;amp;n
from RawData;
select distinct ddate
into :d1 - :d&amp;amp;m
from RawData;
quit;

%put &amp;amp;e1;
%put &amp;amp;e2;
%put &amp;amp;e3;
%put &amp;amp;d1;
%put &amp;amp;d2;
%put &amp;amp;d3;
%put &amp;amp;d4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the log reads:&lt;/P&gt;
&lt;PRE&gt;36         %put &amp;amp;e1;
P01
37         %put &amp;amp;e2;
P02
38         %put &amp;amp;e3;
P03
39         %put &amp;amp;d1;
1801
40         %put &amp;amp;d2;
1802
41         %put &amp;amp;d3;
1803
42         %put &amp;amp;d4;
1804
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2019 08:45:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-03-06T08:45:02Z</dc:date>
    <item>
      <title>into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540665#M149186</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;I am using into statement in proc sql.&lt;BR /&gt;In this example I get an error&lt;BR /&gt;"&lt;BR /&gt;WARNING: Apparent symbolic reference E not resolved.&lt;BR /&gt;9057 &amp;amp;E&amp;amp;N., :D1 - :&amp;amp;D&amp;amp;M.&lt;BR /&gt;."&lt;BR /&gt;What is wrong here please?&lt;/P&gt;
&lt;P&gt;Data RawData;&lt;BR /&gt;Input EMPID $3. Ddate $5. Y 9.;&lt;BR /&gt;cards;&lt;BR /&gt;P01 1801 258766 &lt;BR /&gt;P01 1802 92139678 &lt;BR /&gt;P01 1803 921396 &lt;BR /&gt;P01 1804 898755 &lt;BR /&gt;P02 1801 566511 &lt;BR /&gt;P02 1802 464467896 &lt;BR /&gt;P02 1803 87932&lt;BR /&gt;P02 1804 97931&lt;BR /&gt;P03 1801 73771 &lt;BR /&gt;P03 1802 846420987&lt;BR /&gt;P03 1803 346987 &lt;BR /&gt;P03 1804 744534 &lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT count(distinct EMPID)&lt;BR /&gt;INTO :N &lt;BR /&gt;FROM RawData;&lt;BR /&gt;QUIT; &lt;BR /&gt;%put &amp;amp;N ;/*3*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT count(distinct Ddate)&lt;BR /&gt;INTO :M &lt;BR /&gt;FROM RawData;&lt;BR /&gt;QUIT; &lt;BR /&gt;%put &amp;amp;M ;/*4*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;PROC SQL NOPRINT;&lt;BR /&gt;SELECT DISTINCT EMPID, Ddate &lt;BR /&gt;INTO :E1 - :&amp;amp;E&amp;amp;N., :D1 - :&amp;amp;D&amp;amp;M. &lt;BR /&gt;FROM RawData;&lt;BR /&gt;QUIT; &lt;BR /&gt;%put &amp;amp;E1 ; &lt;BR /&gt;%put &amp;amp;E2 ;&lt;BR /&gt;%put &amp;amp;E3 ;&lt;BR /&gt;%put &amp;amp;D1 ;&lt;BR /&gt;%put &amp;amp;D2 ;&lt;BR /&gt;%put &amp;amp;D3 ;&lt;BR /&gt;%put &amp;amp;D4 ;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540665#M149186</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-06T07:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540670#M149190</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;PLEASE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="2"&gt; use the "little running man" for posting code, the main posting window scrambled your code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Why do you use a reference to macro variable E when you never defined it?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I guess you wanted&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;into :E1 - :E&amp;amp;N.,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540670#M149190</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T07:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540672#M149192</link>
      <description>If the first element in your list of macro variables is this:&lt;BR /&gt;&lt;BR /&gt;E1&lt;BR /&gt;&lt;BR /&gt;then the last element should be this:&lt;BR /&gt;&lt;BR /&gt;&amp;amp;N&lt;BR /&gt;&lt;BR /&gt;not this:&lt;BR /&gt;&lt;BR /&gt;&amp;amp;E%N.&lt;BR /&gt;&lt;BR /&gt;Also note, &amp;amp;N and &amp;amp;M contain leading blanks that you will need to remove.  Here's the simple way to do that.  Immediately after creating them (where you added %put statements) also add:&lt;BR /&gt;&lt;BR /&gt;%let n = &amp;amp;n;&lt;BR /&gt;&lt;BR /&gt;and &lt;BR /&gt;&lt;BR /&gt;%let m = &amp;amp;m;</description>
      <pubDate>Wed, 06 Mar 2019 07:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540672#M149192</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-06T07:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540673#M149193</link>
      <description>Sorry, should be this:&lt;BR /&gt;&lt;BR /&gt;E&amp;amp;N&lt;BR /&gt;&lt;BR /&gt;not this:&lt;BR /&gt;&lt;BR /&gt;&amp;amp;E&amp;amp;N.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540673#M149193</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-06T07:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540674#M149194</link>
      <description>&lt;P&gt;Great and thank you.&lt;/P&gt;
&lt;P&gt;The solution is working great now after applying your tips&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawData;
Input  EMPID $3. Ddate $5. Y 9.;
cards;
P01 1801 258766    
P01 1802 92139678  
P01 1803 921396 
P01 1804 898755   
P02 1801 566511   
P02 1802 464467896 
P02 1803 87932
P02 1804 97931
P03 1801 73771  
P03 1802 846420987
P03 1803 346987 
P03 1804 744534   
;
Run;

PROC SQL NOPRINT;
SELECT count(distinct EMPID)
INTO :N    
FROM RawData;
QUIT; 
%put &amp;amp;N   ;/*3*/
%let N=&amp;amp;N.; /*To remove blanks*/

PROC SQL NOPRINT;
SELECT count(distinct Ddate)
INTO :M    
FROM RawData;
QUIT; 
%put &amp;amp;M   ;/*4*/
%let M=&amp;amp;M.; /*To remove blanks*/


 
PROC SQL NOPRINT;
SELECT DISTINCT EMPID, Ddate    
INTO :E1 - :E&amp;amp;N., :D1 - :D&amp;amp;M.    
FROM RawData;
QUIT; 
%put &amp;amp;E1   ; 
%put &amp;amp;E2   ;
%put &amp;amp;E3   ;
%put &amp;amp;D1   ;
%put &amp;amp;D2   ;
%put &amp;amp;D3   ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540674#M149194</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-06T07:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540694#M149200</link>
      <description>&lt;P&gt;This will not give you your intended result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL NOPRINT;
SELECT DISTINCT EMPID, Ddate    
INTO :E1 - :E&amp;amp;N., :D1 - :D&amp;amp;M.    
FROM RawData;
QUIT; 
%put &amp;amp;E1   ; 
%put &amp;amp;E2   ;
%put &amp;amp;E3   ;
%put &amp;amp;D1   ;
%put &amp;amp;D2   ;
%put &amp;amp;D3   ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See this log snippet:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;68         %put &amp;amp;E1   ;
P01
69         %put &amp;amp;E2   ;
P01
70         %put &amp;amp;E3   ;
P01
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the output of the select is this (if run without noprint):&lt;/P&gt;
&lt;PRE&gt;EMPID  Ddate
------------
P01    1801 
P01    1802 
P01    1803 
P01    1804 
P02    1801 
P02    1802 
P02    1803 
P02    1804 
P03    1801 
P03    1802 
P03    1803 
P03    1804 
&lt;/PRE&gt;
&lt;P&gt;The Ex macro variables catch the &lt;EM&gt;first three&lt;/EM&gt; observations, the Dx the &lt;EM&gt;first four&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;In order to get what you want (my guess), you need to run two separate select into's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct empid
into :e1 - :e&amp;amp;n
from RawData;
select distinct ddate
into :d1 - :d&amp;amp;m
from RawData;
quit;

%put &amp;amp;e1;
%put &amp;amp;e2;
%put &amp;amp;e3;
%put &amp;amp;d1;
%put &amp;amp;d2;
%put &amp;amp;d3;
%put &amp;amp;d4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the log reads:&lt;/P&gt;
&lt;PRE&gt;36         %put &amp;amp;e1;
P01
37         %put &amp;amp;e2;
P02
38         %put &amp;amp;e3;
P03
39         %put &amp;amp;d1;
1801
40         %put &amp;amp;d2;
1802
41         %put &amp;amp;d3;
1803
42         %put &amp;amp;d4;
1804
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 08:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540694#M149200</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T08:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540696#M149201</link>
      <description>&lt;P&gt;Note how this (once again) illustrates the non-usefulness of macro variable lists. Data belongs in datasets, and can very easily be transformed into usable dynamic entities (hash objects, formats, joins) WITHOUT the &lt;STRONG&gt;ab&lt;/STRONG&gt;use of the macro preprocessor.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 08:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540696#M149201</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T08:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540704#M149206</link>
      <description>&lt;P&gt;Pretty much all of it.&amp;nbsp; All of which has been mentioned to you multiple times.&amp;nbsp; Coding all in uppercase to start with, not using code window.&amp;nbsp; Do not put data into macro variables, avoid macro loops as you already have the data available.&amp;nbsp; End macro variables with a final dot.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 09:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540704#M149206</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-06T09:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: into statement in proc sql-get error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540711#M149212</link>
      <description>&lt;P&gt;Just to add to what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a data warehouse administrator / chief developer / maintainer for a quite large company for ~ 20 years now, and I did not even know about the "select - into" feature of SQL until some three years ago (I learned thanks to the communities) because I NEVER needed that. NEVER. And I still haven't used it anywhere in our production jobs. If I need to preserve a &lt;EM&gt;specific&lt;/EM&gt; item in a macro variable, I use call symput, and I never use macro variable lists. Once again, NEVER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right now, I advise you to "forget" that the macro preprocessor even exists, and solve your issues with Base SAS. Your posts repeatedly show how abusing the macro preprocessor only serves to get in your way.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 09:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/into-statement-in-proc-sql-get-error/m-p/540711#M149212</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T09:21:45Z</dc:date>
    </item>
  </channel>
</rss>

