<?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 Advanced calculations in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733667#M28589</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a data set like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=",";
length Test_place $100 Method $20;
input Test_place $ method $ capacity;
datalines;
Test place Toronto,Normal,599
Test place Toronto,Close contact,23
Test place Copenhagen,Normal,699
Test place Copenhagen,Close contact,23
Test Place Thisted,Normal,159
Test Place Thisted,Close contact,15
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="102.43243243243244%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;Method&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;Capacity&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center Toronto&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;599&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center Toronto&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;close contact&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Copenhagen&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;699&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Test Center Copenhagen&lt;/TD&gt;
&lt;TD&gt;close contact&lt;/TD&gt;
&lt;TD&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Thisted&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;159&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Thisted&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;close contact&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;500&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make two new datasets out of this dataset (I have more observations in the real one)&lt;/P&gt;
&lt;P&gt;The first dataset should contain all test center who has capacity over 400, but the matching "close contact" center should follow with, even though it can have below 400.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The second dataset should only contain test centers below 400 and the matching close contact center should follow with IF the matching close contact is below 400.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do these statements?&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 11:04:58 GMT</pubDate>
    <dc:creator>mmea</dc:creator>
    <dc:date>2021-04-14T11:04:58Z</dc:date>
    <item>
      <title>Advanced calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733667#M28589</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a data set like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=",";
length Test_place $100 Method $20;
input Test_place $ method $ capacity;
datalines;
Test place Toronto,Normal,599
Test place Toronto,Close contact,23
Test place Copenhagen,Normal,699
Test place Copenhagen,Close contact,23
Test Place Thisted,Normal,159
Test Place Thisted,Close contact,15
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="102.43243243243244%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;Method&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;Capacity&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center Toronto&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;599&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test center Toronto&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;close contact&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Copenhagen&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;699&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Test Center Copenhagen&lt;/TD&gt;
&lt;TD&gt;close contact&lt;/TD&gt;
&lt;TD&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Thisted&lt;/TD&gt;
&lt;TD width="25%"&gt;Normal&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;159&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Test Center Thisted&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%"&gt;close contact&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;500&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make two new datasets out of this dataset (I have more observations in the real one)&lt;/P&gt;
&lt;P&gt;The first dataset should contain all test center who has capacity over 400, but the matching "close contact" center should follow with, even though it can have below 400.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The second dataset should only contain test centers below 400 and the matching close contact center should follow with IF the matching close contact is below 400.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do these statements?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 11:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733667#M28589</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-04-14T11:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733669#M28590</link>
      <description>&lt;P&gt;Please provide your dataset in a data step with datalines, so we can be sure about variable attributes and contents.&lt;/P&gt;
&lt;P&gt;Like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="," dsd;
input test_center:$50. capacity;
datalines;
Test center Toronto,460
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 10:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733669#M28590</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-14T10:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733678#M28591</link>
      <description>&lt;P&gt;I have edited the question and table&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 11:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733678#M28591</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-04-14T11:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733685#M28592</link>
      <description>&lt;P&gt;With that data, it can be done in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=",";
length Test_place $100 Method $20;
input Test_place $ method $ capacity;
datalines;
Test place Toronto,Normal,599
Test place Toronto,Close contact,23
Test place Copenhagen,Normal,699
Test place Copenhagen,Close contact,23
Test Place Thisted,Normal,159
Test Place Thisted,Close contact,15
;

data
  over400
  under400
;
set have;
by test_place notsorted;
retain cap;
if first.test_place then cap = capacity;
if cap ge 400
then output over400;
else output under400;
drop cap;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's important that the "Normal" observation always comes first in a group. If it does not, a merge with itself will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by test_place;
run;

data
  over400
  under400
;
merge
  have
  have (
    in=o400
    rename=(method=_m capacity=_cap)
    where=(_m = "Normal" and _cap ge 400)
  )
;
by test_place;
if o400
then output over400;
else output under400;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 11:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Advanced-calculations/m-p/733685#M28592</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-14T11:22:38Z</dc:date>
    </item>
  </channel>
</rss>

