BookmarkSubscribeRSS Feed
blowsnow__
Calcite | Level 5

Greetings all,

 

I am trying to read the following data set into one observation for each sales associate. First of all, how can I ignore the first meaningless line? And suppose I only want the output to show three variables - Name, Latest Sales Date, and Total Sales. For the dates column, how can I create the variable "Latest Sales Date" that only indicates the most recent date from each salesperson? In addition, how can I create the other variable "Total Sales" that sums up the total sales amount of each person?

 

1234567890123456789012345678901234567890

David Wong     1/Aug/2018  13200  

Brian Leung    15/Sep/2018 23450

               10/Sep/2018 33000

Mary Chan      3/Jul/2018  45600

               20/Aug/2018 37800

               1/Sep/2018  21500

               30/Aug/2018 42000

John Tam       12/Sep/2018 35000

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

How is this data stored? Already in a sas data set or a txt/Excel file?

blowsnow__
Calcite | Level 5

This data is stored as a .txt file

PeterClemmensen
Tourmaline | Level 20

ok. First, read your data into a SAS data set like this. Simply inset the relevant path instead of path

 

data have;
   length name $15;
   infile "path.txt" firstobs=2;
   input name $ 1-15 date:date11. sales;
   format date date11.;
run;
Tom
Super User Tom
Super User

You just need to retain the name.

data want ;
  infile 'myfile.txt' truncover ;
  length Dummy Name $15 Latest_Sales_Date Total_Sales 8;
  input dummy $15.  Latest_Sales_Date date11. Total_Sales ;
  format Latest_Sales_Date date9.;
  retain name;
  name=coalescec(dummy,name);
  drop dummy;
run;
blowsnow__
Calcite | Level 5

Well the output shows several observations for each person. What if I only want one observation for each salesperson, with their most recent sales date and sum of total sales instead?

Tom
Super User Tom
Super User

Use PROC SUMMARY.


@blowsnow__ wrote:

Well the output shows several observations for each person. What if I only want one observation for each salesperson, with their most recent sales date and sum of total sales instead?


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1320 views
  • 0 likes
  • 3 in conversation