BookmarkSubscribeRSS Feed
jb9977
Fluorite | Level 6

 

I have a dataset
FiscalDate    year    Value
01JAN2012   2012     2
14JAN2012    2012    3
15JAN2012    2012     4
04FEB2012    2012     6
05FEB2012    2012     7
01JAN2013     2013    1
12JAN2013    2013     2
08MAR2014   2014    10
09MAR2014    2014    11
If it is the first instance of the year and has a value of 2 than it should be reduced by 1. Here is the output that I need
FiscalDate   year   Value
01JAN2012  2012    1
14JAN2012   2012   2
15JAN2012   2012   3
04FEB2012    2012   5
05FEB2012    2012    6
01JAN2013     2013    1
12JAN2013     2013    2
08MAR2014    2014   10
09MAR2014     2014   11


Data is sorted by date

1 REPLY 1
Astounding
PROC Star

As long as YEAR is also part of the data set, you can use it:

 

data want;

set have;

by year;

if first.year then do;

   if value=2 then increment = -1;

   else increment = 0;

end;

retain increment;

value = value + increment;

run;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 1 reply
  • 363 views
  • 1 like
  • 2 in conversation