BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
newbi
SAS Employee

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_KEYRIDSales
03/01/20141$1000
03/02/20141$1500
03/03/20141$2000
03/05/20142$1000
03/06/20143$5000

Result i want:

Date_KEYRIDSalesSales Start Day
03/01/20141$10001
03/02/20141$15002
03/03/20141$20003
03/05/20142$10001
03/06/20143$50001

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data want;

set have; /* your dataset name */

by rid;

if first.rid then sales_start_day=0;

sales_start_day+1;

run;

View solution in original post

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

data want;

set have; /* your dataset name */

by rid;

if first.rid then sales_start_day=0;

sales_start_day+1;

run;

Quentin
Super User

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

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
newbi
SAS Employee

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 965 views
  • 0 likes
  • 3 in conversation