Creating a Person-Period Data Set

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

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

100100103
100010203
100001313
1011..111

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
Respected Advisor
Posts: 4,819

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

View solution in original post


All Replies
Super User
Posts: 19,167

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
Respected Advisor
Posts: 4,819

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 457 views
  • 4 likes
  • 3 in conversation