<?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: Checking loop number. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16046#M2227</link>
    <description>i=1 corresponds to A, i=2 corresponds to B, and so on.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q1:&lt;/B&gt; If I would like to name my new data sets TableOutA, TableOutB, and so on, would that be possible? Using a macrovariable inside each data step?&lt;BR /&gt;
&lt;BR /&gt;
In data set TableOutA there should only be persons with Choice=A, and so on.&lt;BR /&gt;
&lt;BR /&gt;
I had several variables besides the variable Choice. I would like to keep only CHOICE, IDENTITY and SALARY.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q2:&lt;/B&gt; It looks like it's not possible with a (KEEP= IDENTITY CHOICE SALARY) in the OUTPUT statement. &lt;BR /&gt;
Do I have to do the keeping (or dropping) in a separate step?&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q3:&lt;/B&gt; If the correspondence between &lt;B&gt;i&lt;/B&gt; and the values of CHOICE were arbitrary would that complicate things?&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;As I said: This is a simplification of the real case. I have reasons to use a macro. &lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
    <pubDate>Tue, 07 Apr 2009 13:05:22 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-07T13:05:22Z</dc:date>
    <item>
      <title>Checking loop number.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16044#M2225</link>
      <description>In the table, TableIn, there is a variabel, Choice, that can take any of the 20 character values A - T.&lt;BR /&gt;
Depending on the value of Choice I want to create 20 different smaller tables.&lt;BR /&gt;
If the macro code looks something like this:&lt;BR /&gt;
&lt;BR /&gt;
%MyMacro;&lt;BR /&gt;
&lt;BR /&gt;
%DO i=1 %TO 20;&lt;BR /&gt;
&lt;BR /&gt;
DATA TableOut&amp;amp;i.;&lt;BR /&gt;
SET TableIn;&lt;BR /&gt;
&lt;BR /&gt;
Pseudocode: IF Choice  nr i THEN OUTPUT TableOut&amp;amp;i.;&lt;BR /&gt;
&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
This is a simple description of a more complicated situation.&lt;BR /&gt;
&lt;BR /&gt;
In my real case I &lt;B&gt;REALLY WANT&lt;/B&gt; to use a macro with a do loop, although it's not necessary in my example.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way inside the data step to check the value of &lt;B&gt;i&lt;/B&gt;?&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Tue, 07 Apr 2009 10:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16044#M2225</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-07T10:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Checking loop number.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16045#M2226</link>
      <description>Since you don't really describe the relation between Choice and how this value affects the creation of the 20 tables, it's hard to give a qualified answer. But on your direct question: yes, &amp;amp;i is available in the data step. So your pseudo code should work. Macro variables are evaluated at data step compile time, which will in your case since your %do-loop wraps around a complete data step.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 07 Apr 2009 12:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16045#M2226</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-04-07T12:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Checking loop number.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16046#M2227</link>
      <description>i=1 corresponds to A, i=2 corresponds to B, and so on.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q1:&lt;/B&gt; If I would like to name my new data sets TableOutA, TableOutB, and so on, would that be possible? Using a macrovariable inside each data step?&lt;BR /&gt;
&lt;BR /&gt;
In data set TableOutA there should only be persons with Choice=A, and so on.&lt;BR /&gt;
&lt;BR /&gt;
I had several variables besides the variable Choice. I would like to keep only CHOICE, IDENTITY and SALARY.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q2:&lt;/B&gt; It looks like it's not possible with a (KEEP= IDENTITY CHOICE SALARY) in the OUTPUT statement. &lt;BR /&gt;
Do I have to do the keeping (or dropping) in a separate step?&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Q3:&lt;/B&gt; If the correspondence between &lt;B&gt;i&lt;/B&gt; and the values of CHOICE were arbitrary would that complicate things?&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;As I said: This is a simplification of the real case. I have reasons to use a macro. &lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Tue, 07 Apr 2009 13:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16046#M2227</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-07T13:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Checking loop number.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16047#M2228</link>
      <description>perhaps you can use this as an foundation for your further work (please post your solution)&lt;BR /&gt;
[pre]&lt;BR /&gt;
data input;&lt;BR /&gt;
  input Choice $ value;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
A 1&lt;BR /&gt;
B 2&lt;BR /&gt;
C 2&lt;BR /&gt;
D 3&lt;BR /&gt;
E 3&lt;BR /&gt;
F 4&lt;BR /&gt;
; run;&lt;BR /&gt;
 &lt;BR /&gt;
%macro sqlloop(input,byvar,keep,output);&lt;BR /&gt;
 proc sql NOPRINT;  &lt;BR /&gt;
  select distinct &amp;amp;byvar. into :_values SEPARATED by " &amp;amp;output."&lt;BR /&gt;
  from &amp;amp;input.;&lt;BR /&gt;
 quit; &lt;BR /&gt;
 &lt;BR /&gt;
 data &amp;amp;output.&amp;amp;_values.;  &lt;BR /&gt;
  set &amp;amp;input.;  &lt;BR /&gt;
  keep &amp;amp;keep.;&lt;BR /&gt;
  select (&amp;amp;byvar);    &lt;BR /&gt;
  %do i=1 %to %sysfunc(count(&amp;amp;output.&amp;amp;_values.,&amp;amp;output.));      &lt;BR /&gt;
   %let var = %sysfunc(scan(&amp;amp;output.&amp;amp;_values.,&amp;amp;i.));       &lt;BR /&gt;
   when ("%substr(&amp;amp;var.,%length(&amp;amp;output.)+1)") &lt;BR /&gt;
   output &amp;amp;var.;    &lt;BR /&gt;
   %end;  &lt;BR /&gt;
  end;&lt;BR /&gt;
 run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
 &lt;BR /&gt;
%sqlloop(input=input, byvar=Choice, keep=value, output=TableOut);&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 07 Apr 2009 13:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-loop-number/m-p/16047#M2228</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-04-07T13:28:01Z</dc:date>
    </item>
  </channel>
</rss>

