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_ID | DELIVERY_DATE | WEEK_YEAR | DELIVERY_YEAR | DELIVERY_WEEK | NEW_COLUMN |
| 10000048 | 21/12/2009 | 51 - 2009 | 2009 | 51 | 1 |
| 10000048 | 23/12/2009 | 51 - 2009 | 2009 | 51 | 1 |
| 10000048 | 28/12/2009 | 52 - 2009 | 2009 | 52 | 2 |
| 10000048 | 30/12/2009 | 52 - 2009 | 2009 | 52 | 2 |
| 10000048 | 04/01/2010 | 1 - 2010 | 2010 | 1 | 3 |
| 10000048 | 08/01/2010 | 1 - 2010 | 2010 | 1 | 3 |
| 10000048 | 11/01/2010 | 2 - 2010 | 2010 | 2 | 4 |
Many Thanks Art![]()
Add this line of code.
if first.delivery_week then new_column+1;
Many Thanks Art![]()
As a variation of ArtC's suggestion:
new_column+first.delivery_week;
Haikuo
yours is cleaner Haikuo - thanks
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
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.