<?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: SAS SQL INTO CLAUSE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366991#M275268</link>
    <description>&lt;P&gt;The problem is occurring because macro variables hold character strings.&amp;nbsp; Instead of getting "4" as the value of &amp;amp;n, SQL is converting the value 4 to a character string, and inserting leading blanks as part of the conversion process.&amp;nbsp; The solution is relatively easy.&amp;nbsp; Insert this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can go anywhere after the SELECT statement that creates &amp;amp;n (before or after the QUIT statement doesn't matter).&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2017 14:51:06 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-06-14T14:51:06Z</dc:date>
    <item>
      <title>SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366987#M275267</link>
      <description>&lt;P&gt;Hello all;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a dataset like this&lt;/P&gt;&lt;P&gt;Country Sales&lt;/P&gt;&lt;P&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&lt;/P&gt;&lt;P&gt;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&lt;/P&gt;&lt;P&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;600&lt;/P&gt;&lt;P&gt;D &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;800&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create datasets for individual countries, Like in above example there are 4 distnict countries so i want to create 4 datasets using proc sql into clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a patial code which is given below-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;input country $ sales;&lt;BR /&gt;cards;&lt;BR /&gt;a 100&lt;BR /&gt;b 200&lt;BR /&gt;a 400&lt;BR /&gt;c 500&lt;BR /&gt;z 800&lt;BR /&gt;;&lt;BR /&gt;run; proc print; run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;selecct count(distinct(country)) into :n&lt;BR /&gt;from work.new;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select distinct(country) into :var1-:var&amp;amp;n.&amp;nbsp;&lt;BR /&gt;from work.info;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are showing some error in 2nd sql command because i am not able to see&amp;nbsp;&lt;/P&gt;&lt;P&gt;a in &amp;amp;var1&lt;/P&gt;&lt;P&gt;b in &amp;amp;var2&lt;/P&gt;&lt;P&gt;etc..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you guys help me out, where I am comminting mistake and to complete the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 14:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366987#M275267</guid>
      <dc:creator>Ankur32</dc:creator>
      <dc:date>2017-06-14T14:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366991#M275268</link>
      <description>&lt;P&gt;The problem is occurring because macro variables hold character strings.&amp;nbsp; Instead of getting "4" as the value of &amp;amp;n, SQL is converting the value 4 to a character string, and inserting leading blanks as part of the conversion process.&amp;nbsp; The solution is relatively easy.&amp;nbsp; Insert this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can go anywhere after the SELECT statement that creates &amp;amp;n (before or after the QUIT statement doesn't matter).&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 14:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366991#M275268</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-14T14:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366992#M275269</link>
      <description>&lt;P&gt;In your code you use something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count(distinct(make)) into :n
from sashelp.cars;
quit;

%put NOTE: *&amp;amp;n*;
%let n = &amp;amp;n;
%put NOTE: *&amp;amp;n*;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when you look at the content of the macro var N, the first %PUT, you will see that you have leading blanks, they propably cause the error. A simple assignment statement will remove the leading blanks and everything will be fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on your SAS version you might also be able to use the TRIMMED option after the :n&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 14:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366992#M275269</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-06-14T14:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366996#M275270</link>
      <description>&lt;P&gt;You can also fix it as you create the macro variable. e.g.:&lt;/P&gt;
&lt;PRE&gt;data new;
input country $ sales;
cards;
a 100
b 200
a 400
c 500
z 800
;
run; 

proc sql;
  select strip(put(count(distinct(country)),8.)) into :n
    from work.new
  ;
quit;

proc sql;
  select distinct(country) into :var1- :var&amp;amp;n. 
    from work.new
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 15:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366996#M275270</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-14T15:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366997#M275271</link>
      <description>&lt;P&gt;Another option is to use a single proc sql and then you don't need to worry about &amp;amp;n:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;input country $ sales;&lt;BR /&gt;cards;&lt;BR /&gt;a 100&lt;BR /&gt;b 200&lt;BR /&gt;a 400&lt;BR /&gt;c 500&lt;BR /&gt;z 800&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select distinct(country) into :var1-:var9999&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; from work.new;&lt;BR /&gt;quit;&lt;BR /&gt;%let n = &amp;amp;sqlobs;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... Martha&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 15:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/366997#M275271</guid>
      <dc:creator>sasmih</dc:creator>
      <dc:date>2017-06-14T15:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367013#M275272</link>
      <description>&lt;P&gt;This topic has been touched many times, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;had a very nice summary, I couldn't find his original post, but this is what I have saved:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2    proc sql noprint ;

3      select max(age) into :a1 from sashelp.class;

4    %put a1=|&amp;amp;a1|;

a1=|      16|

5    %let a1=&amp;amp;a1;

6    %put a1=|&amp;amp;a1|;

a1=|16|

7

8      select max(age) into :a1 - :a1 from sashelp.class;

9    %put a1=|&amp;amp;a1|;

a1=|16|

10

11     select max(age) into :a1 separated by 'anything' from sashelp.class;

12   %put a1=|&amp;amp;a1|;

a1=|16|

13

14   * SAS 9.3 or higher ;

15     select max(age) into :a1 -  from sashelp.class;

16   %put a1=|&amp;amp;a1|;

a1=|16|

17

18     select max(age) into :a1 trimmed from sashelp.class;

19   %put a1=|&amp;amp;a1|;

a1=|16|

20   quit;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jun 2017 15:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367013#M275272</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-06-14T15:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367378#M275273</link>
      <description>&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;selecct count(distinct(country)) into :n &lt;STRONG&gt;separated by ' '&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from work.new;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select distinct(country) into :var1-:var&lt;STRONG&gt;%left(&amp;amp;n)&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from work.info;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 14:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367378#M275273</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-15T14:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL INTO CLAUSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367427#M275274</link>
      <description>&lt;P&gt;Now I want 4 datasets for separte separte countries which contains the country and their sales.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i write this code-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro name ()&lt;/P&gt;&lt;P&gt;%do i=1 to&amp;amp;n.;&lt;/P&gt;&lt;P&gt;data &amp;amp;&amp;amp;country&amp;amp;i..;&lt;/P&gt;&lt;P&gt;set work.new;&lt;/P&gt;&lt;P&gt;where country=&amp;amp;&amp;amp;country&amp;amp;i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend name();&lt;/P&gt;&lt;P&gt;% name ();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i am not able to create datasets like country1 country2..and so on..&lt;/P&gt;&lt;P&gt;and i have one more doubt, where these datasets will be available, will I have to use libname to save these datasets in a particular location, if yes then how it will use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 16:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-INTO-CLAUSE/m-p/367427#M275274</guid>
      <dc:creator>Ankur32</dc:creator>
      <dc:date>2017-06-15T16:20:17Z</dc:date>
    </item>
  </channel>
</rss>

