I have these data
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 |
Suppose that raw data file SalesRecords.txt (not provided) is stored in the subfolder 'C:\Temp'. A part of the data file is shown in the table below. The first line in the shown table is not part of the data file. The records are grouped by the salesperson’s name. The first record for each salesperson includes the salesperson’s name (characters, columns 1-15, contain embedded blanks), the date of sales (dd/mon/yyyy, columns 16-26), and the amount of sales (standard numeric, columns 28-32). Subsequent records of the same salesperson, if any, are stored with blank name field. The data set does not contain missing value in the other fields.
Write a SAS program that reads each record of SalesRecords.txt into a SAS data set named Sales_Total. Sales_Total must be in the following form:
You are allowed to include only one DATA step in your SAS program. Keep in mind that some salespersons in the raw data file may have only 1 record, and the records of the same salespersons are not sorted in the order of date. The first few observations of Sales_Total are displayed below:
Show the code you already have, and where it does not work as expected.
Use the proper windows for posting code, data and logs (see my footnotes).
@Makmatt wrote:
I have these data
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
Suppose that raw data file SalesRecords.txt (not provided) is stored in the subfolder 'C:\Temp'. A part of the data file is shown in the table below. The first line in the shown table is not part of the data file. The records are grouped by the salesperson’s name. The first record for each salesperson includes the salesperson’s name (characters, columns 1-15, contain embedded blanks), the date of sales (dd/mon/yyyy, columns 16-26), and the amount of sales (standard numeric, columns 28-32). Subsequent records of the same salesperson, if any, are stored with blank name field. The data set does not contain missing value in the other fields.
Write a SAS program that reads each record of SalesRecords.txt into a SAS data set named Sales_Total. Sales_Total must be in the following form:
- It contains only one observation for each salesperson.
- Each observation contains only the following variables in this order: the salesperson’s name, the salesperson’s latest sales date, the number of days between the salesperson’s latest sales date and the 30th of September 2018, the salesperson’s total sales, and the running total of sales for all salespersons.
You are allowed to include only one DATA step in your SAS program. Keep in mind that some salespersons in the raw data file may have only 1 record, and the records of the same salespersons are not sorted in the order of date. The first few observations of Sales_Total are displayed below:
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: