BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Question
Fluorite | Level 6

Hi All,

This should be very quick for you, I would like to add a new column that count weeks like below...

I know how to count number of rows, but here, it's different, I want to say for example week51 and year 2009 is Week1 like below. Your help will be mucg appreciated.

Thanks

  CUST_10000048_V2; 

  SET CUST_10000048;

  RETAIN COUNTER;

  BY SOLD_TO_ORG_ID DELIVERY_YEAR DELIVERY_WEEK;

  IF FIRST.SOLD_TO_ORG_ID AND FIRST.DELIVERY_YEAR AND FIRST.DELIVERY_WEEK THEN COUNTER=0;

  COUNTER=COUNTER+1;

  ;

SOLD_TO_ORG_IDDELIVERY_DATEWEEK_YEARDELIVERY_YEARDELIVERY_WEEKNEW_COLUMN
1000004821/12/200951 - 20092009511
1000004823/12/200951 - 20092009511
1000004828/12/200952 - 20092009522
1000004830/12/200952 - 20092009522
1000004804/01/20101 - 2010201013
1000004808/01/20101 - 2010201013
1000004811/01/20102 - 2010201024
1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
ArtC
Rhodochrosite | Level 12

Add this line of code.

if first.delivery_week then new_column+1;

Question
Fluorite | Level 6

Many Thanks ArtSmiley Happy

Haikuo
Onyx | Level 15

As a variation of ArtC's suggestion:

new_column+first.delivery_week;

Haikuo

ArtC
Rhodochrosite | Level 12

yours is cleaner Haikuo - thanks

PGStats
Opal | Level 21

An alternative would be :

proc rank data=myData out=want;

BY SOLD_TO_ORG_ID DELIVERY_YEAR;

var delivery_week;

ranks new_column;

run;

PG

PG

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
  • 5 replies
  • 836 views
  • 0 likes
  • 4 in conversation