## Creating a new variable

Occasional Contributor
Posts: 16

# Creating a new variable

[ Edited ]

On the attached file is a assessment that I have to complete but i'm having trouble with questions part 1a and 1b. I'm not to sure how I can approach this problem so I was hoping so one can lead me in the right direction. As of now I have the data imported:

/*printing out import*/

proc print data = uchi (obs = 10);
run;

proc sort data = uchi;
by person_id;
run;

proc print data = uchi (obs = 100);
run;

/*creating numeric dates*/

data case;
set uchi;
informat arrest_date yymmdd10. dispos_date yymmdd10.;
if arrest_date < dispos_date then re_arrest = 1;
run;

proc print data = case (obs = 10);
format arrest_date yymmdd10.;
run;

Super User
Posts: 23,319

## Re: Creating a new variable

Looks like you're trying to calculate a moving cumulative total. Do you have SAS ETS? If so, try PROC EXPAND. If not, if you search moving statistics you'll find a ton of examples on here or online on how to calculate moving statistics in SAS.

ogarduno wrote:

On the attached file is a assessment that I have to complete but i'm having trouble with questions part 1a and 1b. I'm not to sure how I can approach this problem so I was hoping so one can lead me in the right direction. As of now I have the data imported:

/*printing out import*/

proc print data = uchi (obs = 10);
run;

proc sort data = uchi;
by person_id;
run;

proc print data = uchi (obs = 100);
run;

/*creating numeric dates*/

data case;
set uchi;
informat arrest_date yymmdd10. dispos_date yymmdd10.;
if arrest_date < dispos_date then re_arrest = 1;
run;

proc print data = case (obs = 10);
format arrest_date yymmdd10.;
run;

Super User
Posts: 13,338

## Re: Creating a new variable

"questions part 1a and 1b" are what exactly? If there was an attempt to attach something it apparently did not get attached.

If the questions are plain text no need to "attach" anything. Open a code box using the {I} menu icon, copy the text from your document and paste into the box.

Highlighted
Super User
Posts: 23,319

## Re: Creating a new variable

@ballardw He attached his full assignment which I suggested he remove, it had personal information.

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