<?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 **Urgent!!! How can I set the 'name' as array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777509#M247371</link>
    <description>&lt;P&gt;I only want to keep the last record of each name, how can I deal with it? Should I actually use the array function or sth else?&lt;/P&gt;</description>
    <pubDate>Sun, 31 Oct 2021 06:15:42 GMT</pubDate>
    <dc:creator>user1029</dc:creator>
    <dc:date>2021-10-31T06:15:42Z</dc:date>
    <item>
      <title>**Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777509#M247371</link>
      <description>&lt;P&gt;I only want to keep the last record of each name, how can I deal with it? Should I actually use the array function or sth else?&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 06:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777509#M247371</guid>
      <dc:creator>user1029</dc:creator>
      <dc:date>2021-10-31T06:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777513#M247373</link>
      <description>&lt;P&gt;Sort by name and dateofsales, then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by name;
if last.name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Oct 2021 15:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777513#M247373</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-30T15:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777518#M247377</link>
      <description>&lt;P&gt;I need to perform the tasks within the same DATA step.&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 06:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777518#M247377</guid>
      <dc:creator>user1029</dc:creator>
      <dc:date>2021-10-31T06:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777520#M247379</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404909"&gt;@user1029&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I need to perform the tasks within the same DATA step, and after I add the code into my SAS coding, it displays an error.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't understand why it has to be in the same data step. Above, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; did not say to add it into your existing DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, when someone says "it displays an error" but doesn't show us the code they are using or what the error is ... it's really impossible to help you. Please show us the LOG so we can see both the code and the error.&lt;/P&gt;</description>
      <pubDate>Sat, 30 Oct 2021 17:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777520#M247379</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-30T17:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777533#M247385</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404909"&gt;@user1029&lt;/a&gt;&amp;nbsp;Looks like you and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404932"&gt;@Cheggg1111&lt;/a&gt;&amp;nbsp;got the same homework.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate that you've given that first a try on your own and shared your code with the data step creating the sample data included.&lt;/P&gt;
&lt;P&gt;Below something that should work for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd truncover;
  input name :$20. dateOfSales :date11. SalesAmount;
  datalines;
David Wong,1/Sep/2021,13200
Brian Leung,15/Sep/2021,23450
Brian Leung,10/Sep/2021,33000
Mary Chan,3/Sep/2021,45600
Mary Chan,20/Sep/2021,37800
Mary Chan,1/Aug/2021,21500
Mary Chan,30/Aug/2021,42000
John Tam,12/Sep/2021,35000
;

proc sort data=have;
  by name dateOfSales;
run;

data want;
  set have;
  by name dateOfSales;
  totalSales+SalesAmount;
  if last.name then
    do;
      salesName=name;
      format latestDate ddmmyyS10.;
      latestDate=dateOfSales;
      salesDays=dateOfSales - '30/Sep/2021'd;
      output;
      call missing(totalSales);
    end;
  keep salesName latestDate salesDays totalSales;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 00:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777533#M247385</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-11-01T00:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777544#M247388</link>
      <description>&lt;P&gt;Run the data step with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by name notsorted;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Retain a variable to keep the max of dates, and another for the sum:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain max_date sum_sales;
if first.name
then do,
  max_date = .;
  sum_sales = 0;
end,
max_date = max(max_date,salesdate);
sum_sales + sales;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At last.name, calculate the date difference and OUTPUT.&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 06:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777544#M247388</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-31T06:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: **Urgent!!! How can I set the 'name' as array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777569#M247402</link>
      <description>&lt;PRE&gt;data have;
  infile datalines dsd truncover;
  input name :$20. dateOfSales :date11. SalesAmount;
  datalines;
David Wong,1/Sep/2021,13200
Brian Leung,15/Sep/2021,23450
Brian Leung,10/Sep/2021,33000
Mary Chan,3/Sep/2021,45600
Mary Chan,20/Sep/2021,37800
Mary Chan,1/Aug/2021,21500
Mary Chan,30/Aug/2021,42000
John Tam,12/Sep/2021,35000
;

proc sql;
create table want as
select name,max(dateOfSales) as LastSaleDate,sum(SalesAmount) as TotalSales,
 '30Sep2021'd-calculated LastSaleDate as daysbetween
 from have
  group by name;
quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 31 Oct 2021 11:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-How-can-I-set-the-name-as-array/m-p/777569#M247402</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-31T11:10:02Z</dc:date>
    </item>
  </channel>
</rss>

