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

Hi

I'm trying to adjust my dataset as follows:

The "before" dataset below is a sample from my existing dataset; the "after" is where I want it to be. Basically, the vehicle_years field is populated in the first entry of each year and then if there is a change over the year the change is given; all other entries are 0. I want (for each policy and each year) to cumulate the initial figure over each following transaction in the same year.     

data before;
infile datalines dlm=',';
input policy_no  year  vehicle_nos 5. ;
datalines ;
123,2010,1233
123,2010,1
123,2010,0
123,2011,1234
123,2011,0
123,2011,1
123,2011,0
123,2011,4
123,2012,1234
123,2012,0
123,2012,1
124,2010,12345
124,2010,0
124,2010,0
124,2011,12445
124,2011,0
124,2011,1
124,2012,13444
124,2012,0
124,2012,0
run;


data after;
infile datalines dlm=',';
input policy_no  year  vehicle_nos 5. ;
datalines ;
123,2010,1233
123,2010,1234
123,2010,1234
123,2011,1234
123,2011,1234
123,2011,1235
123,2011,1235
123,2011,1239
123,2012,1234
123,2012,1234
123,2012,1235
124,2010,12345
124,2010,12345
124,2010,12345
124,2011,12345
124,2011,12345
124,2011,12346
124,2012,13444
124,2012,13444
124,2012,13444
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

data after (drop=vno);

set before (rename=(vehicle_nos=vno));

by policy_no year;

retain vehicle_nos;

if first.year

then vehicle_nos = vno;

else vehicle_nos = vehicle_nos + vno;

run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

data after (drop=vno);

set before (rename=(vehicle_nos=vno));

by policy_no year;

retain vehicle_nos;

if first.year

then vehicle_nos = vno;

else vehicle_nos = vehicle_nos + vno;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 768 views
  • 0 likes
  • 2 in conversation