<?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: Data set creation using existing data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8967#M417</link>
    <description>Hi Chuck, &lt;BR /&gt;
&lt;BR /&gt;
THanks! -- would it be possible for you to provide an example? I see the syntax for do-while loops but I am not sure how I would code the condition to loop until the end of the data set.  So, I would have something like this right... &lt;BR /&gt;
&lt;BR /&gt;
data dummy;&lt;BR /&gt;
set accounts;&lt;BR /&gt;
keep interval acc# bal1 bal2;&lt;BR /&gt;
do until (last row of the intervals table)&lt;BR /&gt;
   if bal1 &amp;gt; min1 &amp;amp; bal1&lt;MAX1&gt;min2 &amp;amp; bal2&lt;MAX2&gt;&lt;BR /&gt;
   then interval = grpnm;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
In the above, how would I specify that I want to iterate on rows in the intervals dataset. how would I specify that when I meet the if condition, I should include the row in the new dummy dataset and use the value of grpnm from intervals at the particular row i stopped? &lt;BR /&gt;
&lt;BR /&gt;
Thanks again. &lt;BR /&gt;
Elena&lt;/MAX2&gt;&lt;/MAX1&gt;</description>
    <pubDate>Thu, 03 Apr 2008 21:25:41 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-04-03T21:25:41Z</dc:date>
    <item>
      <title>Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8965#M415</link>
      <description>I am having trouble creating a dataset using information in 2 other data sets: intervals and accounts. Basically I want to break down data from the accounts dataset based on the intervals in the intervals dataset to create a 3rd dataset which has each account and it's interval name listed. &lt;BR /&gt;
&lt;BR /&gt;
My intervals data set looks like this: &lt;BR /&gt;
&lt;BR /&gt;
grpnm   min1   max1   min2   max2&lt;BR /&gt;
a1        0         50       0        50&lt;BR /&gt;
a2        0         50       100    150&lt;BR /&gt;
b1        50      100       200    300&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
My second data set looks like this: &lt;BR /&gt;
acc#    bal1    bal2&lt;BR /&gt;
h1       20      20&lt;BR /&gt;
h2       40      45&lt;BR /&gt;
h3       75      250&lt;BR /&gt;
h4       35      125&lt;BR /&gt;
h5       80      201&lt;BR /&gt;
&lt;BR /&gt;
My end goal is to produce a dataset like this: &lt;BR /&gt;
&lt;BR /&gt;
grpnm   acc#    bal1   bal2&lt;BR /&gt;
a1         h1       20     20&lt;BR /&gt;
a1         h2       40     45&lt;BR /&gt;
a2         h4       35     125&lt;BR /&gt;
a3         h3       75     250&lt;BR /&gt;
a3         h5       80     201&lt;BR /&gt;
&lt;BR /&gt;
I can't use a join since the datasets have nothing in common. I was thinking of a loop but i wasn't sure how I would loop only on one dataset in a DATA step. Anybody have any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance!!!</description>
      <pubDate>Thu, 03 Apr 2008 19:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8965#M415</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-03T19:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8966#M416</link>
      <description>I see two approaches to the problem:&lt;BR /&gt;
&lt;BR /&gt;
1)  For each data observation, test the intervals and output appropriately.&lt;BR /&gt;
2)  For each interval, test the data and output appropriately.&lt;BR /&gt;
&lt;BR /&gt;
To implement #2, I see more than one way:&lt;BR /&gt;
1)  data dummy; set interval; call execute ... to call a macro &lt;BR /&gt;
2)  internal loop in the data step to step through the data&lt;BR /&gt;
&lt;BR /&gt;
To implement #1, I think an internal loop in the data step to run through the interval conditions makes most sense.</description>
      <pubDate>Thu, 03 Apr 2008 20:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8966#M416</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-03T20:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8967#M417</link>
      <description>Hi Chuck, &lt;BR /&gt;
&lt;BR /&gt;
THanks! -- would it be possible for you to provide an example? I see the syntax for do-while loops but I am not sure how I would code the condition to loop until the end of the data set.  So, I would have something like this right... &lt;BR /&gt;
&lt;BR /&gt;
data dummy;&lt;BR /&gt;
set accounts;&lt;BR /&gt;
keep interval acc# bal1 bal2;&lt;BR /&gt;
do until (last row of the intervals table)&lt;BR /&gt;
   if bal1 &amp;gt; min1 &amp;amp; bal1&lt;MAX1&gt;min2 &amp;amp; bal2&lt;MAX2&gt;&lt;BR /&gt;
   then interval = grpnm;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
In the above, how would I specify that I want to iterate on rows in the intervals dataset. how would I specify that when I meet the if condition, I should include the row in the new dummy dataset and use the value of grpnm from intervals at the particular row i stopped? &lt;BR /&gt;
&lt;BR /&gt;
Thanks again. &lt;BR /&gt;
Elena&lt;/MAX2&gt;&lt;/MAX1&gt;</description>
      <pubDate>Thu, 03 Apr 2008 21:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8967#M417</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-03T21:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8968#M418</link>
      <description>Real easy with PROC SQL. &lt;BR /&gt;
&lt;BR /&gt;
Don't get stuck in a rut that you have to have something in common to join.&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA=DATA1;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA=DATA2;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
CREATE TABLE DATA3 AS&lt;BR /&gt;
	SELECT &lt;BR /&gt;
		GRPNM,&lt;BR /&gt;
		ACCT,&lt;BR /&gt;
		BAL1,&lt;BR /&gt;
		BAL2&lt;BR /&gt;
	FROM&lt;BR /&gt;
		DATA1,&lt;BR /&gt;
		DATA2&lt;BR /&gt;
	WHERE &lt;BR /&gt;
		BAL1 BETWEEN MIN1 AND MAX1&lt;BR /&gt;
		AND&lt;BR /&gt;
		BAL2 BETWEEN MIN2 AND MAX2;&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA=DATA3;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 Obs    GRPNM    MIN1    MAX1    MIN2    MAX2&lt;BR /&gt;
&lt;BR /&gt;
     1      A1        0       50       0      50&lt;BR /&gt;
     2      A2        0       50     100     150&lt;BR /&gt;
     3      A3       50      100     200     300&lt;BR /&gt;
&lt;BR /&gt;
Obs    ACCT    BAL1    BAL2&lt;BR /&gt;
&lt;BR /&gt;
     1      H1      20       20&lt;BR /&gt;
     2      H2      40       45&lt;BR /&gt;
     3      H3      75      250&lt;BR /&gt;
     4      H4      35      125&lt;BR /&gt;
     5      H5      80      201&lt;BR /&gt;
&lt;BR /&gt;
Obs    GRPNM    ACCT    BAL1    BAL2&lt;BR /&gt;
&lt;BR /&gt;
     1      A1       H1      20       20&lt;BR /&gt;
     2      A1       H2      40       45&lt;BR /&gt;
     3      A3       H3      75      250&lt;BR /&gt;
     4      A2       H4      35      125&lt;BR /&gt;
     5      A3       H5      80      201&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ike Eisenhauer</description>
      <pubDate>Thu, 03 Apr 2008 21:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8968#M418</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-03T21:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8969#M419</link>
      <description>Thanks Ike, that worked!&lt;BR /&gt;
&lt;BR /&gt;
I'm still curious about how I would loop through two dataset with different types of data in it using Do-Until, but for now at least I can get some work done!</description>
      <pubDate>Thu, 03 Apr 2008 21:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8969#M419</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-03T21:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data set creation using existing data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8970#M420</link>
      <description>The Proc SQL solution is better and more elegant.  I hadn't thought through the problem enough to realize that the implicit cartesian join was actually desirable in this case.&lt;BR /&gt;
&lt;BR /&gt;
To do the loop, you need to read about the set command and the dataset options.&lt;BR /&gt;
You can use multiple sets in a data step, so you would place one inside the loop, and one outside the loop.  The one inside the loop would have to have the appropriate options set to capture the end of the file (end=eof).  I'm not sure how to reset back to the beginning.  You may need to use random access, requesting the observation specifically by number.&lt;BR /&gt;
&lt;BR /&gt;
But, I wouldn't waste any time on the looping methodology.</description>
      <pubDate>Fri, 04 Apr 2008 14:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-set-creation-using-existing-data-sets/m-p/8970#M420</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-04T14:11:24Z</dc:date>
    </item>
  </channel>
</rss>

