<?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 sets with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387837#M93015</link>
    <description>&lt;P&gt;Potentially, you might be omitting important information here.&amp;nbsp; Some questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does each data set contain the data for just a single PERSON_ID?&amp;nbsp; (If there are multiple PERSON_IDs within a single data set, is each data set in order BY PERSON_ID?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible that multiple data sets refer to the same PERSON_ID?&amp;nbsp; (If so, should the report for that PERSON_ID list the person only once, grouping all&amp;nbsp;claims from all data sets below?)&lt;/P&gt;</description>
    <pubDate>Mon, 14 Aug 2017 16:10:43 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-08-14T16:10:43Z</dc:date>
    <item>
      <title>how to print multiple data sets with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387831#M93010</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some data sets: work.data1, work.data2, work.data3 .... work.data1000. I would like to output them with do&amp;nbsp;loop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a similar question(&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Using-a-do-loop-to-load-multiple-data-sets/m-p/345867#M79645" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Using-a-do-loop-to-load-multiple-data-sets/m-p/345867#M79645&lt;/A&gt;) and wrote following SAS codes, however, it doesn't work out correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.data1;
input person_id claim_id $ var1 var2 var3;
datalines;
1 ab 12 23 34
1 cc 34 45 32
1 ee 56 32 55
run;

data work.data2;
input person_id claim_id $ var1 var2 var3;
datalines;
2 gh 11 22 23 
2 cd 34 67 43
;
run;




%macro Data;

%local i;
%do i=1 %to 2;

data _null_;
file print PS = 32767;

set work.data&amp;amp;i end=lastrec;

if _N_ eq 1 then do;&lt;BR /&gt;put '[';
put ' "PERSON_ID":' PERSON_ID +(-1)',';
end;
put '{';
put ' "claim_id":' claim_id +(-1)',';
put ' "days":' var2 +(-1)',';


if lastrec eq 1 then do;
put '}';&lt;BR /&gt;put ']';
end;

else do;
put '},';
end;

run;
%end;
%mend;

%Data;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It prints out separately. There are two outputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I only want one whole output, like following:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Any help will be appreciated!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;PRE class="batch"&gt;[                                                                                                 
 "PERSON_ID":1,                                                                                   
{                                                                                                 
 "claim_id":ab,                                                                                   
 "days":23,                                                                                       
},                                                                                                
{                                                                                                 
 "claim_id":cc,                                                                                   
 "days":45,                                                                                       
},                                                                                                
{                                                                                                 
 "claim_id":ee,                                                                                   
 "days":32,                                                                                       
}                                                                                                 
],&lt;/PRE&gt;&lt;PRE class="batch"&gt;[                                                                                                 
 "PERSON_ID":2,                                                                                   
{                                                                                                 
 "claim_id":gh,                                                                                   
 "days":22,                                                                                       
},                                                                                                
{                                                                                                 
 "claim_id":cd,                                                                                   
 "days":67,                                                                                       
}&lt;BR /&gt;]&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Aug 2017 15:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387831#M93010</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-08-14T15:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data sets with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387833#M93011</link>
      <description>&lt;P&gt;I don't think you need a macro, or if you do the loop needs to be defined differently for sure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one that I think does what you want. Note that I redirected this to an output file, since I assume that's the end goal anyways.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined / view=combined;
set data1-data2;
run;


data _null_;
file 'c:\_localdata\temp.txt';

set combined end=lastrec;
by person_id notsorted;

if first.person_id then do;
put '[';
put ' "PERSON_ID":' PERSON_ID +(-1)',';
end;
put '{';
put ' "claim_id":' claim_id +(-1)',';
put ' "days":' var2 +(-1)',';


if lastrec eq 1 then do;
put '}';put ']';
end;

else do;
put '},';
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Aug 2017 16:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387833#M93011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-14T16:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data sets with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387837#M93015</link>
      <description>&lt;P&gt;Potentially, you might be omitting important information here.&amp;nbsp; Some questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does each data set contain the data for just a single PERSON_ID?&amp;nbsp; (If there are multiple PERSON_IDs within a single data set, is each data set in order BY PERSON_ID?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible that multiple data sets refer to the same PERSON_ID?&amp;nbsp; (If so, should the report for that PERSON_ID list the person only once, grouping all&amp;nbsp;claims from all data sets below?)&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2017 16:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387837#M93015</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-14T16:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to print multiple data sets with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387850#M93021</link>
      <description>&lt;P&gt;Thank you sooo&amp;nbsp;much!!! I was thinking too much!!! You are right! I even subsetted a giant data set to multiple&amp;nbsp;datasets by their ID in order to print out them. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2017 16:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-print-multiple-data-sets-with-do-loop/m-p/387850#M93021</guid>
      <dc:creator>wy110</dc:creator>
      <dc:date>2017-08-14T16:28:54Z</dc:date>
    </item>
  </channel>
</rss>

