Solved
Contributor
Posts: 29

Creating a Person-Period Data Set

[ Edited ]

Hi,

I'm trying to make a dataset that contains one record per phone call, and this dataset contains many phone calls to sample unit (household) level. I have created a variable, count1, that counts each phone call to sample unit level. I am trying to make dummy variables that indicate which call number each record in the dataset is, something similar to this:

id time1 time2 time3 count event callstoevent

 100 1 0 0 1 0 3 100 0 1 0 2 0 3 100 0 0 1 3 1 3 101 1 . . 1 1 1

I want an array that will create a dummy variable(time[i]) for each call up until this count (0 for each variable before the count, and 1 at the count). I then want my time[i] variable to equal . after time[i]=1. I currently can only figure out how to program my time[i] variables to be either 0 or 1, and not with the missing value after time[i]=1.

Here is my code:

data new;

set old;

array time[1:116] time1-time116;

do i=1 to dim(time);

if count=1 then time[i]=1;

else time[i]=0;

end;

run;

Does anyone know of a way where I can kick SAS out of this array, and stop processing after time[i]=1, and then set all values of time[i] to . after time[i]=1? As you can probably guess with the 116 time variables in my dataset, most households will not have this many calls made to their house, and thus should be coded from 0 until time[i]=1, and . thereafter.

Thank you so much,

Kevin

Accepted Solutions
Solution
‎02-22-2016 10:37 PM
Posts: 5,521

Re: Creating a Person-Period Data Set

As @Reeza mentioned, your example is not consistent. You either want:

data new;
set old;
array time time1-time116;
do i = 1 to dim(time) until(event and i = count);
time{i} = i = count;
end;
run;

/* or */

data new;
set old;
array time time1-time116;
do i = 1 to dim(time) until(i = count);
time{i} = i = count;
end;
run;
PG

All Replies
Super User
Posts: 23,683

Re: Creating a Person-Period Data Set

I think you need to post some better sample data, specifically what your input data set looks like and what you want your output data set to look like.

Is it possible to set it to all values to missing ( .) first, and then fill in your 0/1 as you go through?

Solution
‎02-22-2016 10:37 PM
Posts: 5,521

Re: Creating a Person-Period Data Set

As @Reeza mentioned, your example is not consistent. You either want:

data new;
set old;
array time time1-time116;
do i = 1 to dim(time) until(event and i = count);
time{i} = i = count;
end;
run;

/* or */

data new;
set old;
array time time1-time116;
do i = 1 to dim(time) until(i = count);
time{i} = i = count;
end;
run;
PG
Contributor
Posts: 29

Re: Creating a Person-Period Data Set

Thanks guys! I did a terrible job of asking that question, but @PGStats code from his first solution ended up working for me.

Thanks!

🔒 This topic is solved and locked.