<?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: Looping through a large number of numeric values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366788#M275232</link>
    <description>&lt;P&gt;Can bext skilton code help you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table list as
      select distinct Var1 
      from work.dataname
      order by var1;
quit;

proc sort dataname; by var1; run;

data want;
  merge list dataname;
  by var1;
       if first.var1 then do; &amp;lt;initializing code&amp;gt;; end;
       ... code to be done taken from the "loop" ...
       if last.var1 then do; &amp;lt;finalizing code&amp;gt;; end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Jun 2017 23:22:42 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-06-13T23:22:42Z</dc:date>
    <item>
      <title>Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366776#M275227</link>
      <description>&lt;P&gt;I'm trying to do conditional analyses based on a variable taking on every possible unique values there is. Say I want to do a proc freq on Var2 conditional on Var1 being equal to one of the many values it could take on. I used to do the following thing to grab all unique values of Var1 before looping through it:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct Var1&amp;nbsp;into: allvalues separated by ' ' from work.dataname&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;That worked well for categorical variables with limited number of values, but now Var1 is numeric and can take on 100,000 possible values. Doing the procedure above would crash SAS becasue the string gets too long. Can someone write a macro for what I want to achieve including the following frequency procedure?&lt;/P&gt;&lt;P&gt;proc freq data=dataname;&lt;/P&gt;&lt;P&gt;table Var2;&lt;/P&gt;&lt;P&gt;where Var1=(looping through all unique values taken on by Var1);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 21:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366776#M275227</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-06-13T21:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366779#M275228</link>
      <description>&lt;P&gt;And what is your plan to utilize 100,000 reports?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can easily get what you are asking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by var1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;by var1;&lt;/P&gt;
&lt;P&gt;tables var2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what happens next?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 22:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366779#M275228</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-13T22:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366780#M275229</link>
      <description>Thanks. I am doing something that may require looping through the values. That frequency was just an example, I realize that it's not a good example.</description>
      <pubDate>Tue, 13 Jun 2017 22:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366780#M275229</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-06-13T22:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366781#M275230</link>
      <description>&lt;P&gt;if possible, please show a small representative sample what you have and what you want. So that it will easy for someone to help you&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 22:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366781#M275230</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-13T22:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366786#M275231</link>
      <description>&lt;P&gt;Well, whatever approach you take you will still have 100,000 sets of reports (assuming you can wait for the program to finish). &amp;nbsp;But I leave that part to you. &amp;nbsp;Here is a way to approach this that will make this feasible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro every_a (dsn);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;create table every_a as select distinct a from &amp;amp;dsn;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %local i a_value;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set every_a (firstobs=&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; call symputx('a_value', a);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; stop;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; *** Add what you would like here, to process the current value of A which is stored in &amp;amp;A_VALUE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend every_a;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 23:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366786#M275231</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-13T23:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366788#M275232</link>
      <description>&lt;P&gt;Can bext skilton code help you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table list as
      select distinct Var1 
      from work.dataname
      order by var1;
quit;

proc sort dataname; by var1; run;

data want;
  merge list dataname;
  by var1;
       if first.var1 then do; &amp;lt;initializing code&amp;gt;; end;
       ... code to be done taken from the "loop" ...
       if last.var1 then do; &amp;lt;finalizing code&amp;gt;; end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jun 2017 23:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366788#M275232</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-13T23:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366847#M275233</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69320"&gt;@apolitical&lt;/a&gt;: assuming from your initial question that you already have a macro which does the report for one value. You could then either use CALL EXECUTE or write the statements to a file for %INCLUDE. I prefer the latter, as you have the option to take a look at your generated file before submitting, and you can submit it statement by statement when testing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;filename tempsas temp;
data _null_;
  set dataname;
  by Var1;
  if first.Var1;
  file tempsas;
  put '%report_macro(' Var1 ');';
run;&lt;/PRE&gt;&lt;P&gt;When developing/testing you can then open the TEMPSAS file, take a good look at it, and if it looks OK you can use the SUBTOP command to test the first couple of statements.&lt;/P&gt;&lt;P&gt;When the test is OK, you can instead put the line&lt;/P&gt;&lt;PRE&gt;%include tempsas;&lt;/PRE&gt;&lt;P&gt;into your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 05:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/366847#M275233</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-06-14T05:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a large number of numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/367879#M275234</link>
      <description>thanks . i ended up not going forward with this, but this works.</description>
      <pubDate>Fri, 16 Jun 2017 20:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-large-number-of-numeric-values/m-p/367879#M275234</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-06-16T20:17:00Z</dc:date>
    </item>
  </channel>
</rss>

