<?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: Blank datasets created in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361766#M85367</link>
    <description>&lt;P&gt;One way would be to add another sql step and use it to determine whether to create the dataset. e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select make 
    from sashelp.cars
      where make="&amp;amp;c" and type = "&amp;amp;d"
  ;

   %if &amp;amp;sqlobs. gt 0 %then %do;
    create table &amp;amp;c._&amp;amp;d as select * from sashelp.cars where make="&amp;amp;c" and type = "&amp;amp;d";
   %end;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 20:20:47 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-05-25T20:20:47Z</dc:date>
    <item>
      <title>Blank datasets created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361761#M85364</link>
      <description>&lt;P&gt;Below is my code. This basically is a macro which creates dataset based on make and type from sashelp.cars. The output is just fine. But it also creates DS where there are 0 observations. Can someone help me figure out how can I not have those pls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro new;

proc sql noprint;
select distinct make into : a separated by "@" from sashelp.cars;
select distinct type into : b separated by "@" from sashelp.cars;
select count (distinct make) into :n separated by "@" from sashelp.cars;
select count (distinct type) into : m separated by "@" from sashelp.cars;

quit;

%put &amp;amp;a. &amp;amp;n. &amp;amp;b. &amp;amp;m.;

%do i = 1 %to &amp;amp;n;
%do j = 1 %to &amp;amp;m;
%let c = %scan(&amp;amp;a,&amp;amp;i,"@");
%let d = %scan(&amp;amp;b,&amp;amp;j,"@");

proc sql;
create table &amp;amp;c._&amp;amp;d as select * from sashelp.cars where make="&amp;amp;c" and type = "&amp;amp;d";
quit;

%end;
%end;


%mend;
%new;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 20:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361761#M85364</guid>
      <dc:creator>adityaa9z</dc:creator>
      <dc:date>2017-05-25T20:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Blank datasets created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361766#M85367</link>
      <description>&lt;P&gt;One way would be to add another sql step and use it to determine whether to create the dataset. e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select make 
    from sashelp.cars
      where make="&amp;amp;c" and type = "&amp;amp;d"
  ;

   %if &amp;amp;sqlobs. gt 0 %then %do;
    create table &amp;amp;c._&amp;amp;d as select * from sashelp.cars where make="&amp;amp;c" and type = "&amp;amp;d";
   %end;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 20:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361766#M85367</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-25T20:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Blank datasets created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361767#M85368</link>
      <description>&lt;P&gt;Insert before the QUIT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;sqlobs=0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; drop table &amp;amp;c._&amp;amp;d;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that some combinations of values just don't exist in the source data.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 20:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361767#M85368</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-25T20:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Blank datasets created</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361831#M85390</link>
      <description>&lt;P&gt;I hope you're doing this to learn macro's and not anything else - &lt;A href="http://www.sascommunity.org/wiki/Split_Data_into_Subsets" target="_self"&gt;99% of the time splitting datasets like this is not a good idea.&lt;/A&gt;&amp;nbsp;See the other ways to do this in the link above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Besides the solutions above, my recommendation would to make sure you have only all valid type, make combinations and create only those. That would require maybe creating a single variable that could be parsed. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct catx("@", make, type) into :var_list1-
from sashelp.cars;
quit;

%let n = &amp;amp;sqlobs;

%put &amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 00:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Blank-datasets-created/m-p/361831#M85390</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-26T00:18:26Z</dc:date>
    </item>
  </channel>
</rss>

