Would someone be able to offer advice on how I can do the following:
Based on date_key i would like to create new column which can provide Sales start day (1st day of sale). For example:
| Date_KEY | RID | Sales |
|---|---|---|
| 03/01/2014 | 1 | $1000 |
| 03/02/2014 | 1 | $1500 |
| 03/03/2014 | 1 | $2000 |
| 03/05/2014 | 2 | $1000 |
| 03/06/2014 | 3 | $5000 |
Result i want:
| Date_KEY | RID | Sales | Sales Start Day |
|---|---|---|---|
| 03/01/2014 | 1 | $1000 | 1 |
| 03/02/2014 | 1 | $1500 | 2 |
| 03/03/2014 | 1 | $2000 | 3 |
| 03/05/2014 | 2 | $1000 | 1 |
| 03/06/2014 | 3 | $5000 | 1 |
Thanks in advance.
data want;
set have; /* your dataset name */
by rid;
if first.rid then sales_start_day=0;
sales_start_day+1;
run;
data want;
set have; /* your dataset name */
by rid;
if first.rid then sales_start_day=0;
sales_start_day+1;
run;
Hi,
Not sure I follow your logic, but I think below will make your WANT table:
data want;
set have;
by RID Date_Key;
if first.RID then SalesStartDay=0;
if first.Date_Key then SalesStartDay ++ 1;
run;
HTH
Thanks for all your help.
Linlin solutin worked:
data want;
set have; /* your dataset name */
by rid;
if first.rid then sales_start_day=0;
sales_start_day+1;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.