<?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 please help: NODUPKEY does not accumulate values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278149#M55941</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to work with a sample data about people's visit to a certain state and sort out whether each person has visited&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the capital (Washington D.C ) or not and how many times each person visited there by flight.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The major problem I am having is grouping with the new variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my sample data .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID= personal identification number&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FLIGHT_TICKET_N= flight ticket number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STATE = state in the U.S (DC=Washington D.C, captial city of the U.S)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data VISIT;&lt;BR /&gt;input ID$ FLIGHT_TICKET_N STATE$;&lt;BR /&gt;cards;&lt;BR /&gt;10063 1111 DC&lt;BR /&gt;10063 1112 DC&lt;BR /&gt;10063 1113 DC&lt;BR /&gt;10073 2221 DC&lt;BR /&gt;10073 2223 TX&lt;BR /&gt;10083 3331 CA&lt;BR /&gt;10083 3332 WA&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data visit;&lt;BR /&gt;set visit;&lt;BR /&gt;captial=".";&lt;BR /&gt;if substr(STATE,1,2) in ("DC") then captial=1;&lt;BR /&gt;if captial ~= 1 then captial=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visit_1;&lt;BR /&gt;set visit;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then acc_capital=0;&lt;BR /&gt;acc_capital + captial;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so far it works as I intended. However, when I tried this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=visit_1 out=visit_2 nodupkey; by ID; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results do not correctly reflect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#1. whether each person has visited the capital city or not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2. the accumulated number of visit to the capital city for each person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as shown in the picture.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really need to figure this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am I would appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12665i051FDD7B7BC2DA15/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="sasq1.jpg" title="sasq1.jpg" /&gt;</description>
    <pubDate>Fri, 17 Jun 2016 10:56:12 GMT</pubDate>
    <dc:creator>sasworker16</dc:creator>
    <dc:date>2016-06-17T10:56:12Z</dc:date>
    <item>
      <title>please help: NODUPKEY does not accumulate values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278149#M55941</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to work with a sample data about people's visit to a certain state and sort out whether each person has visited&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the capital (Washington D.C ) or not and how many times each person visited there by flight.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The major problem I am having is grouping with the new variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my sample data .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID= personal identification number&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FLIGHT_TICKET_N= flight ticket number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STATE = state in the U.S (DC=Washington D.C, captial city of the U.S)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data VISIT;&lt;BR /&gt;input ID$ FLIGHT_TICKET_N STATE$;&lt;BR /&gt;cards;&lt;BR /&gt;10063 1111 DC&lt;BR /&gt;10063 1112 DC&lt;BR /&gt;10063 1113 DC&lt;BR /&gt;10073 2221 DC&lt;BR /&gt;10073 2223 TX&lt;BR /&gt;10083 3331 CA&lt;BR /&gt;10083 3332 WA&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data visit;&lt;BR /&gt;set visit;&lt;BR /&gt;captial=".";&lt;BR /&gt;if substr(STATE,1,2) in ("DC") then captial=1;&lt;BR /&gt;if captial ~= 1 then captial=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visit_1;&lt;BR /&gt;set visit;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then acc_capital=0;&lt;BR /&gt;acc_capital + captial;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so far it works as I intended. However, when I tried this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=visit_1 out=visit_2 nodupkey; by ID; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results do not correctly reflect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#1. whether each person has visited the capital city or not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2. the accumulated number of visit to the capital city for each person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as shown in the picture.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really need to figure this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am I would appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12665i051FDD7B7BC2DA15/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="sasq1.jpg" title="sasq1.jpg" /&gt;</description>
      <pubDate>Fri, 17 Jun 2016 10:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278149#M55941</guid>
      <dc:creator>sasworker16</dc:creator>
      <dc:date>2016-06-17T10:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: please help: NODUPKEY does not accumulate values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278150#M55942</link>
      <description>&lt;P&gt;Sort with nodupkey only removes any records with duplicate keys after encountering the first on, and does not help in accumulating values.&lt;/P&gt;
&lt;P&gt;Other procedures are there for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data VISIT;
input ID$ FLIGHT_TICKET_N STATE$;
cards;
10063 1111 DC
10063 1112 DC
10063 1113 DC
10073 2221 DC
10073 2223 TX
10083 3331 CA
10083 3332 WA
;
run;

data visit;
set visit;
if substr(STATE,1,2) in ("DC")
then capital = 1;
else capital = 0;
run;

proc summary data=visit;
by id;
var capital;
output
  out=want (drop=_type_ _freq_)
  max(capital) = capital
  sum(capital) = acc_capital
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 11:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278150#M55942</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-17T11:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: please help: NODUPKEY does not accumulate values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278563#M56050</link>
      <description>&lt;P&gt;Dear KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help and support.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 01:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/please-help-NODUPKEY-does-not-accumulate-values/m-p/278563#M56050</guid>
      <dc:creator>sasworker16</dc:creator>
      <dc:date>2016-06-20T01:27:33Z</dc:date>
    </item>
  </channel>
</rss>

