BookmarkSubscribeRSS Feed
Ksharp
Super User
data have;
input x $80.;
name=scan(x,-2,'"');
date=input(scan(x,-2,' '),date11.);
sale=input(scan(x,-1,' '),best.);
format date date11.;
drop x;
datalines;
"David Wong" 1/Aug/2023 13200
"Brian Leung" 15/Sep/2023 23450
10/Sep/2023 33000
"Mary Chan" 3/Jul/2023 45600
20/Aug/2023 37800
1/Dec/2023 21500
30/Aug/2023 42000
"John Tam" 12/Sep/2023 35000
;
run;
data temp;
 set have;
 length new_name $ 80;
 retain new_name;
 if not missing(name) then new_name=name;
 drop name;
run;
proc summary data=temp nway;
class new_name;
var sale;
output out=want(drop=_type_ rename=(_freq_=no_of_visit)) sum=Toatl_Spent;
run;
Mike_Chan
Calcite | Level 5

thx for your distribution. But the output should be one observation per person. 

 

The output should be:

Mike_Chan_1-1730192386257.png

Mike_Chan_0-1730192356517.png

 

I am attempting this direction but its stuck rn.

data Totalsales;
input name $quote20. @;

s1 = substr(name,1,1);
If ('A' <= s1 <= 'Z') then do;
          if  _n_ ^=1 then do;

datalines;
"David Wong" 1/Aug/2023 13200
"Brian Leung" 15/Sep/2023 23450
  10/Sep/2023 33000
"Mary Chan" 3/Jul/2023 45600
20/Aug/2023 37800
    1/Dec/2023 21500
 30/Aug/2023 42000
"John Tam" 12/Sep/2023 35000
;
run;

 

 

 

Ksharp
Super User

Why you have to use only one data step to get all of these?

It is totally useless and nonsense .

 

options parmcards=sale;
filename sale temp;
parmcards;
"David Wong" 1/Aug/2023 13200
"Brian Leung" 15/Sep/2023 23450
10/Sep/2023 33000
"Mary Chan" 3/Jul/2023 45600
20/Aug/2023 37800
1/Dec/2023 21500
30/Aug/2023 42000
"John Tam" 12/Sep/2023 35000
;




data have;
infile sale truncover end=last;
length name $ 200;
retain name;
input ;
name=coalescec(scan(_infile_,-2,'"'),name);
date=input(scan(_infile_,-2,' '),date11.);
sale=input(scan(_infile_,-1,' '),best.);
format date last_sale_date date11.;

array n{999999} $ 200 _temporary_;
array d{999999}  _temporary_;
array s{999999}  _temporary_;
n{_n_}=name;
d{_n_}=date;
s{_n_}=sale;
if last then do;
  do i=1 to _n_;
   last_sale_date=max(last_sale_date,d{i});
   number_of_sale+1;
   running_sale_total+s{i};
   if n{i} ne n{i+1} then do;
     new_name=n{i};
     days_between_last_sale_31dec2023='31dec2023'd-last_sale_date;
     output;
	 call missing(last_sale_date,number_of_sale,running_sale_total);
   end;
  end;
end;
keep new_name days_between_last_sale_31dec2023 last_sale_date number_of_sale running_sale_total;
run;

Ksharp_0-1730254045609.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 2484 views
  • 0 likes
  • 8 in conversation