<?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: Output three years with suffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518087#M140164</link>
    <description>&lt;P&gt;First of all, I feel compelled to mention, as other people do, that separating data like this is inefficient and a poor practice. You'd be better off in most situations keeping the data in one data set and then when it comes time to do analysis, use the BY statement to get analyses for each year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When running macros like this, you want to use OPTIONS MPRINT; before the macro so as to make the macro easier to debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When asking for help, saying "This doesn't work" really provides no useful information. Showing us the error (the SAS log) is a much more effective way to get help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The most obvious mistake in your code is that you are missing a semi-colon after&amp;nbsp;OUTPUT and also you need a RUN; statement after the OUTPUT; statement.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Dec 2018 14:37:47 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-12-03T14:37:47Z</dc:date>
    <item>
      <title>Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518082#M140162</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have the following data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp; year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cost&lt;/P&gt;&lt;P&gt;&amp;nbsp;X &amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;&amp;nbsp;X&amp;nbsp;&amp;nbsp;&amp;nbsp; 2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&lt;/P&gt;&lt;P&gt;&amp;nbsp;X&amp;nbsp;&amp;nbsp;&amp;nbsp; 2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 150&lt;/P&gt;&lt;P&gt;Y&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;&amp;nbsp;Y &amp;nbsp;&amp;nbsp; 2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 70&lt;/P&gt;&lt;P&gt;&amp;nbsp;Y &amp;nbsp;&amp;nbsp; 2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 400&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i want separated data tables for each year and tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro Test;&lt;BR /&gt;%do i=2015 %to 2017;&lt;BR /&gt;Data Cost_&amp;amp;i;&lt;BR /&gt;set in;&lt;BR /&gt;If year=&amp;amp;i then output %end;&lt;BR /&gt;%MEND Test;&lt;BR /&gt;&lt;BR /&gt;%Test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This doesnt work. Could you please help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your effort!&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518082#M140162</guid>
      <dc:creator>Dynamike</dc:creator>
      <dc:date>2018-12-03T14:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518087#M140164</link>
      <description>&lt;P&gt;First of all, I feel compelled to mention, as other people do, that separating data like this is inefficient and a poor practice. You'd be better off in most situations keeping the data in one data set and then when it comes time to do analysis, use the BY statement to get analyses for each year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When running macros like this, you want to use OPTIONS MPRINT; before the macro so as to make the macro easier to debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When asking for help, saying "This doesn't work" really provides no useful information. Showing us the error (the SAS log) is a much more effective way to get help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The most obvious mistake in your code is that you are missing a semi-colon after&amp;nbsp;OUTPUT and also you need a RUN; statement after the OUTPUT; statement.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518087#M140164</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-03T14:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518088#M140165</link>
      <description>&lt;P&gt;Write the data step for one year (without any macro action) and compare it to what you create with the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: there's something small but important missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hint-hint: use options mlogic mprint;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:39:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518088#M140165</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-03T14:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518090#M140166</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $   year       Cost;
cards;
 X    2015      100
 X    2016      200
 X    2017     150
Y    2015      30
 Y    2016      70
 Y    2017     400
 ;



proc sql ;                                                              
  create index year on have (year) ;                      
quit ;                                                                  
                                                                        
data _null_ ;                                                           
  if _n_ = 1 then do ;                                                  
    dcl hash h (ordered:'y') ;                                                     
    h.definekey  ("_n_") ;                                              
    h.definedata ('id','year','cost') ;
    h.definedone () ;                                                   
  end ;                                                                 
  do _n_ = 1 by 1 until (last.year) ;                            
    set have ;                                                          
    by year ;                                                    
    h.add() ;                                                           
  end ;                                                                 
  h.output (dataset: catx ("_", "year", year)) ;          
  h.clear() ;                                                           
run ;     &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 14:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518090#M140166</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-03T14:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518112#M140178</link>
      <description>&lt;P&gt;Alternatively with call execute&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $   year       Cost;
cards;
 X    2015      100
 X    2016      200
 X    2017     150
Y    2015      30
 Y    2016      70
 Y    2017     400
 ;
        
proc sql;
create table years as select distinct year from have;
quit;

data _null_;
set years;
call execute('data year_'||strip(year)||'; set have; where year='||year||';run;');
run;	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 15:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518112#M140178</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-03T15:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518136#M140182</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp; Very nice, traditional and simple. I am glad you posted this. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 16:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518136#M140182</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-03T16:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518142#M140185</link>
      <description>I am learning from all the legends in this forum including you. I like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; coding.</description>
      <pubDate>Mon, 03 Dec 2018 16:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518142#M140185</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-03T16:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Output three years with suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518157#M140190</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID $   year       Cost;
cards;
 X    2015      100
 X    2016      200
 X    2017     150
Y    2015      30
 Y    2016      70
 Y    2017     400
 ;

proc sql;
select distinct year into :year  separated by ',' 
from have;
quit;
%macro split/parmbuff;
   %let num=1;
   %let dsname=%scan(&amp;amp;syspbuff,&amp;amp;num);
   %do %while(&amp;amp;dsname ne);
      data year_&amp;amp;dsname;
	  set have;
	  where year=&amp;amp;dsname;
	  run;
      %let num=%eval(&amp;amp;num+1);
      %let dsname=%scan(&amp;amp;syspbuff,&amp;amp;num);
   %end;
%mend split;

%split(&amp;amp;year)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 17:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-three-years-with-suffix/m-p/518157#M140190</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-03T17:15:15Z</dc:date>
    </item>
  </channel>
</rss>

