<?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 proc print data where in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805455#M81697</link>
    <description>&lt;P&gt;hi I would like for my dataset to not be printed to that it doesnt send an email when there are no records. The below is not working though:&lt;/P&gt;
&lt;PRE&gt;proc print data=mydata; 
(where noobs &amp;gt; 0);
run;&lt;/PRE&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2022 08:25:02 GMT</pubDate>
    <dc:creator>Citrine10</dc:creator>
    <dc:date>2022-04-01T08:25:02Z</dc:date>
    <item>
      <title>proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805455#M81697</link>
      <description>&lt;P&gt;hi I would like for my dataset to not be printed to that it doesnt send an email when there are no records. The below is not working though:&lt;/P&gt;
&lt;PRE&gt;proc print data=mydata; 
(where noobs &amp;gt; 0);
run;&lt;/PRE&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805455#M81697</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-04-01T08:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805456#M81698</link>
      <description>&lt;P&gt;You can either have a WHERE= dataset option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mydata (where=(noobs &amp;gt; 0));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or a WHERE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mydata;
where noobs &amp;gt; 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but if you want to only run the PROC PRINT when your dataset has observations, you must do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let noobs = 0; /* in case dataset does not exist */
proc sql noprint;
select nobs int :noobs from dictionary.tables
where libname = "WORK" and memname = "MYDATA";
quit;

%if &amp;amp;noobs. &amp;gt; 0
%then %do;

proc print data=mydata;
run;

%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805456#M81698</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-01T08:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805457#M81699</link>
      <description>thank you Kurt, but what do I do in the instance where there is no observations as there is no records as in that case there wouldnt be an obs column&lt;BR /&gt;ERROR: Variable obs is not on file WORK.Data</description>
      <pubDate>Fri, 01 Apr 2022 08:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805457#M81699</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-04-01T08:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805458#M81700</link>
      <description>&lt;P&gt;Please post your complete log of trying the code I gave you.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805458#M81700</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-01T08:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805461#M81701</link>
      <description>proc print data=data(where=(obs &amp;gt; 0));&lt;BR /&gt;ERROR: Variable obs is not on file WORK.data&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805461#M81701</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-04-01T08:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805462#M81702</link>
      <description>I also tried the below and  get an error:&lt;BR /&gt;&lt;BR /&gt;%let noobs = 0; /* in case dataset does not exist */&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select nobs into :noobs from mydata&lt;BR /&gt;quit;&lt;BR /&gt;%if &amp;amp;noobs. &amp;gt; 0&lt;BR /&gt;%then %do;&lt;BR /&gt;&lt;BR /&gt;	FILENAME MailBox EMAIL&lt;BR /&gt;	TO=(jackie@gmail.com)&lt;BR /&gt;&lt;BR /&gt;	FROM='henr@gmail.com'&lt;BR /&gt;	type='text/html'&lt;BR /&gt;	SUBJECT='Table';&lt;BR /&gt;&lt;BR /&gt;	ODS html body=Mailbox style = noline;&lt;BR /&gt;	ods listing close;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;	proc print data=mydata&lt;BR /&gt;	style (report) = {background = white&lt;BR /&gt;	font_face = "Verdana" font_size = 7pt just=left bordercolor=grey rules=All frame=box}&lt;BR /&gt;	style (column) = {background = white CELLHEIGHT = 2.5%&lt;BR /&gt;	font_face = "Verdana" font_size = 7pt just=left }&lt;BR /&gt;	style (header) = {foreground = cx5e2750 font_face="Verdana"&lt;BR /&gt;	font_size = 8pt just=left&lt;BR /&gt;	};&lt;BR /&gt;		title1 "Table";&lt;BR /&gt;	run;&lt;BR /&gt;	ods html close;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: nobs.</description>
      <pubDate>Fri, 01 Apr 2022 08:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805462#M81702</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-04-01T08:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805463#M81703</link>
      <description>&lt;P&gt;An alternative to dictionary tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro printMe(DS);
data _null_;
  if nobs then call execute (" proc print data=&amp;amp;DS.; run; ");
  stop;
  set &amp;amp;DS. nobs=nobs;
run;
%mend printMe;

%printMe(sashelp.class);


data test;
  x = 42;
  stop;
run;


%printMe(test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 09:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805463#M81703</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-04-01T09:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805464#M81704</link>
      <description>&lt;P&gt;You cannot use a variable in the WHERE that does not exist in the dataset.&lt;/P&gt;
&lt;P&gt;Please explain in clear terms what you want to do.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 09:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805464#M81704</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-01T09:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805465#M81705</link>
      <description>&lt;P&gt;You do not use my code. My code reads the metadata of the MYDATA table from&amp;nbsp;&lt;STRONG&gt;DICTIONARY.TABLES&lt;/STRONG&gt;. Please study my code in detail, and, as already asked, please explain in detail what you want to do.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 09:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805465#M81705</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-01T09:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805736#M81711</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro prnt;
   %if %sysfunc(exist(work.mydata)) %then %do;
      proc print data = work.mydata;
      run;
   %end;
   %else %put dataset does not exist;
 %mend prnt;

%prnt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Apr 2022 17:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/805736#M81711</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-04-03T17:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc print data where</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/807932#M81761</link>
      <description>&lt;P&gt;There are many approaches to solve your issue. I have used the following and it should serve your purpose i.e., print the file if there are observations in the dataset and not when empty.&lt;/P&gt;
&lt;P&gt;I have created an empty dataset called class from sashelp.class and used it to illustrate my code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Creating an empty dataset*/&lt;BR /&gt;proc sql;
create table class like sashelp.class;
quit;
%macro print_if_not_empty(dataset_name);
/* finding the number of observations.*/
data _null_;
set &amp;amp;dataset_name. nobs=obs;
call symputx('nobs',nods);
run;
%if %sysfunc(symexist(nobs)) %then %do;
proc print data=&amp;amp;dataset_name.;
run;
%end;
%else %do;
%put ****The dataset &amp;amp;dataset_name. is empty *****;
%end;
%mend;

/*Call the macro */

%print_if_not_empty(class)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 21:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-print-data-where/m-p/807932#M81761</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-04-14T21:24:23Z</dc:date>
    </item>
  </channel>
</rss>

