<?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: how to print multiple data set at the same time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742412#M232232</link>
    <description>&lt;P&gt;Repeating code is the domain of the macro processor. Wrap your PRINT code into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myprint(ds);
title "&amp;amp;ds.";
proc print data = &amp;amp;ds.;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and call the macro repeatedly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%myprint(A)
%myprint(B)
%myprint(C)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and if you want to further autoamte that, use a dataset and CALL EXECUTE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data control;
input ds $;
datalines;
A
B
C
;

data _null_;
set control;
call execute(cats('%nrstr(%myprint(',ds,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %NRSTR might be needed if you have macro code in the macro, to prevent premature resolution of such.&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 14:40:57 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-05-19T14:40:57Z</dc:date>
    <item>
      <title>how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742406#M232230</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A(keep=y) B(keep=x) C(keep=z);
  
  x=1;
  y=2;
  Z=3;
run;
title 'A';
proc print data = A;
run;
title 'B';
proc print data = B;
run;
title 'C';
proc print data = C;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;above is my code, if I want to print data set A , data set B, data set C ,&amp;nbsp; I need to input the 'proc step' three times ? Is there one method which can print all the three data sets using one proc step?&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 14:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742406#M232230</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-19T14:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742412#M232232</link>
      <description>&lt;P&gt;Repeating code is the domain of the macro processor. Wrap your PRINT code into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myprint(ds);
title "&amp;amp;ds.";
proc print data = &amp;amp;ds.;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and call the macro repeatedly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%myprint(A)
%myprint(B)
%myprint(C)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and if you want to further autoamte that, use a dataset and CALL EXECUTE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data control;
input ds $;
datalines;
A
B
C
;

data _null_;
set control;
call execute(cats('%nrstr(%myprint(',ds,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %NRSTR might be needed if you have macro code in the macro, to prevent premature resolution of such.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 14:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742412#M232232</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T14:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742422#M232237</link>
      <description>&lt;P&gt;There's always another way in SAS.&lt;BR /&gt;The code below creates a macro (multiPrint) that accepts a parameter (dslist that contains your list of datasets). The macro then determines the number of datasets, and runs PROC PRINT on each dataset.&lt;BR /&gt;I added %put statements to help see what happens, you will probably also want to uncomment the options statement to get further debugging information, to help understand what happens.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* options mprint mlogic symbolgen ; */

%macro multiPrint(dslist) ;	
	%let dsCnt=%sysfunc(countw("&amp;amp;dslist")) ;
	%put dsCnt: &amp;amp;dsCnt ;
	%do i=1 %to &amp;amp;dsCnt ;
		%let dsname=%scan(&amp;amp;dslist,&amp;amp;i) ;
		%put &amp;amp;i dsname= &amp;amp;dsname ; 
		
		title "&amp;amp;dsname" ;
		proc print data=&amp;amp;dsname ;
		run ;
	%end ;

%mend ;

data A(keep=y) Bb(keep=x) ccC(keep=z);
  
  x=1;
  y=2;
  Z=3;
run;

%multiPrint(a bb ccc) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 May 2021 14:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742422#M232237</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-19T14:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742429#M232242</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A(keep=y) B(keep=x) C(keep=z);
  
  x=1;
  y=2;
  Z=3;
run;
title 'A';
proc print data = A;
run;
title 'B';
proc print data = B;
run;
title 'C';
proc print data = C;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;above is my code, if I want to print data set A , data set B, data set C ,&amp;nbsp; I need to input the 'proc step' three times ? Is there one method which can print all the three data sets using one proc step?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Basically no. Proc Print handles one data set at a time.&lt;/P&gt;
&lt;P&gt;If the data is structured a bit differently you may be able to combine data sets and create separate output tables for each set using BY processing.&lt;/P&gt;
&lt;PRE&gt;data one;
  input x y;
datalines;
1 11
;
data two;
  input x y;
datalines;
22 222
;
data three;
  input x y;
datalines;
333 3333
;

data combined;
   set one two three indsname=dsname;
   source=dsname;
run;

proc print data=combined;
   by notsorted source;
run;&lt;/PRE&gt;
&lt;P&gt;The key bits here are the SET statement option INDSNAME in the data step creating combined. It creates a temproary variable holding the name of the data set that contributes each record. The Source=dsname makes a permanent variable in the output data set.&lt;/P&gt;
&lt;P&gt;Then the BY in proc print creates a separate output table for each&amp;nbsp; contributing data set. The NOTSORTED option on the BY statement tells SAS the Source variable is not in sorted order so the default behavior of BY group processing causing an error if not sorted BY the values is encountered does not create an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may not do what you want if YOUR data sets have radically different variables because the combined data set would have all the variables and could result in lots of missing values if the specific variables were not that Source data set. Which would be so ugly that the whole process would be questionable in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach is to use the macro language to create a loop based on the names which basically calls proc print multiple times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro dummy(namelist=);
   %do i = 1 %to %sysfunc(countw(&amp;amp;namelist.,,s ));
      %let name= %scan(&amp;amp;namelist.,&amp;amp;i,,s );
      proc print data=&amp;amp;name.;
      run;
   %end;
%mend;

%dummy(namelist= one two three)&lt;/PRE&gt;
&lt;P&gt;Caution: typos or logic errors in macro coding&amp;nbsp; can place a SAS session into an unstable state and appear to quit working.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 14:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742429#M232242</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-19T14:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742446#M232249</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 15:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742446#M232249</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-19T15:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742450#M232253</link>
      <description>&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 15:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742450#M232253</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-19T15:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data set at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742451#M232254</link>
      <description>&lt;P&gt;Thank you, I appreciate.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 15:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-set-at-the-same-time/m-p/742451#M232254</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-19T15:49:14Z</dc:date>
    </item>
  </channel>
</rss>

