<?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: SAs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625575#M184384</link>
    <description>&lt;P&gt;In your class, have you learned about the OUTPUT statement, which can take a data set as an argument?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a hint:&lt;/P&gt;
&lt;P&gt;1. On the DATA statement, list all the data sets that you want to create (for example, A1 and A2).&lt;/P&gt;
&lt;P&gt;2. Use an IF-THEN-ELSE statement to check the value of the A variable and use OUTPUT A1 or OUTPUT A2 to send each observation to the data set that it belongs in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get stuck, there is &lt;A href="https://go.documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1lltvbis7ye1an1eryo4leh2mck.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;an example in the documentation for the OUTPUT statement.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 12:50:26 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2020-02-18T12:50:26Z</dc:date>
    <item>
      <title>How to utilize SAS Programming to explicitly output to multiple datasets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625572#M184383</link>
      <description>&lt;P&gt;data a;&lt;BR /&gt;set sashelp.class nobs=aee;&lt;BR /&gt;a=ceil(_n_/(aee/4));&lt;BR /&gt;b=put(a,words23.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using macro do loops I need all the ones in one dataset and all twos in other datasets using the variable a or b.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 12:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625572#M184383</guid>
      <dc:creator>qazwsx1</dc:creator>
      <dc:date>2020-02-18T12:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625575#M184384</link>
      <description>&lt;P&gt;In your class, have you learned about the OUTPUT statement, which can take a data set as an argument?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a hint:&lt;/P&gt;
&lt;P&gt;1. On the DATA statement, list all the data sets that you want to create (for example, A1 and A2).&lt;/P&gt;
&lt;P&gt;2. Use an IF-THEN-ELSE statement to check the value of the A variable and use OUTPUT A1 or OUTPUT A2 to send each observation to the data set that it belongs in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get stuck, there is &lt;A href="https://go.documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1lltvbis7ye1an1eryo4leh2mck.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;an example in the documentation for the OUTPUT statement.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 12:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625575#M184384</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-18T12:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625589#M184386</link>
      <description>&lt;P&gt;Hi Rich,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;set sashelp.class nobs=aee;&lt;BR /&gt;a=ceil(_n_/(aee/4));&lt;BR /&gt;b=put(a,words23.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=a; by b; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data a13;&lt;BR /&gt;set a ;&lt;BR /&gt;call symput("bc"||compress(_n_),b);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro a(bc,i);&lt;BR /&gt;%do &amp;amp;i= 1 %to 19;&lt;BR /&gt;data &amp;amp;&amp;amp;bc&amp;amp;&amp;amp;i.;&lt;BR /&gt;set a;&lt;BR /&gt;by b;&lt;BR /&gt;if _n_= &amp;amp;i. then output &amp;amp;&amp;amp;bc&amp;amp;&amp;amp;i.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%a(b,i,)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here I'm getting 19 datasets same way I need all the&amp;nbsp; 1,2 3,4 in different datasets&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 12:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625589#M184386</guid>
      <dc:creator>qazwsx1</dc:creator>
      <dc:date>2020-02-18T12:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625596#M184387</link>
      <description>&lt;P&gt;No macro is needed here, as shown in the link I posted. However, if the assignment REQUIRES that you use a macro, then you'll have to figure it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The biggest mistake that new SAS programmers make is to jump into macro programming without understanding the basics of DATA step programming. When people struggle to write a macro, I always advise them to FIRST figure out how to write it without using a macro, AFTER the program works, then modify the program so that the repetitive portions of the program are replaced by macro substitution.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 12:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625596#M184387</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-18T12:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to utilize SAS Programming to explicitly output to multiple datasets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625598#M184388</link>
      <description>&lt;P&gt;Create code dynamically, depending on the contents of variable b:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
set sashelp.class nobs=aee;
a=ceil(_n_/(aee/4));
b=put(a,words23.);
run;

/* get a list if distinct values in b */
proc sort
  data=a (keep=b)
  out=c
  nodupkey
;
by b;
run;

/* use call execute() to create code */
data _null_;
call execute('data'); /* begin a new data step */
do until (end1); /* populate the data statement with dataset names */
  set c end=end1;
  call execute(' ' !! strip(b));
end;
call execute('; set a;'); /* terminate the data statement and define the source dataset */
do until (end2); /* create a series of if/then output statements  */
  set c end=end2;
  call execute('if b = "' !! strip(b) !! '" then output ' !! strip(b) !! ';');
end;
call execute('run;'); /* terminate the data step */
stop; /* stop here, otherwise we would get a single spurious "data" in the execution queue
  from a partial execution of the next data step iteration */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Feb 2020 13:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625598#M184388</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-18T13:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625701#M184452</link>
      <description>&lt;P&gt;So your first step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  set sashelp.class nobs=aee;
  a=ceil(_n_/(aee/4));
  b=put(a,words23.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Makes two variables with the same information.&amp;nbsp; A is a number an B is a string.&amp;nbsp; Let's see how well it worked.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=a;
  tables a*b/list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                                       Cumulative    Cumulative
a    b        Frequency     Percent     Frequency      Percent
---------------------------------------------------------------
1    one             4       21.05             4        21.05
2    two             5       26.32             9        47.37
3    three           5       26.32            14        73.68
4    four            5       26.32            19       100.00&lt;/PRE&gt;
&lt;P&gt;Now it sounds like you want to make 4 datasets using the value of B as the name. (Not sure how well that will work when there are more than twenty groups.)&lt;/P&gt;
&lt;P&gt;So it looks like you want to generate code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one two three four;
  set a;
  if a=1 then output one;
  else if a=2 then output two;
  else if a=3 then output three;
  else if a=4 then output four;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one two three four;
  set a;
  select (a);
    when (1) output one;
    when (2) output two;
    when (3) output three;
    when (4) output four;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So here is a simple way.&amp;nbsp; Since dataset A is sorted by variable A (by definition of how you generated it) we could just use it to drive the process.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  put 'data ' @;
  do until (eof1);
    set a end=eof1;
    by a;
    if first.a then put b @;
  end;
  put ';' / 'set a;' / 'select a;' ;
  do until (eof2);
    set a end=eof2;
    by a;
    if first.a then put 'when (' a ') output ' b ';' ;
  end;
  put 'end;' / 'run;' ;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then to run the generated code just use %INCLUDE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure how MACRO comes into this.&amp;nbsp; Perhaps you could create a macro where you pass in the name of the dataset that is being split and the number of datasets you want to create?&amp;nbsp; If so that will just impact the first step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(datain,number);
data a;
  set &amp;amp;datain. nobs=aee;
  a=ceil(_n_/(aee/&amp;amp;number.));
  b=put(a,words23.);
run;
....
%mend split;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Feb 2020 20:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-utilize-SAS-Programming-to-explicitly-output-to-multiple/m-p/625701#M184452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-18T20:40:39Z</dc:date>
    </item>
  </channel>
</rss>

