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

 

Hi, I have a data set that tracks unique person identifier, and number of activities they had on a website and call center per YearMonth. An example below, I have the first 4 variables. What I would like to do is flag the YearMonth where the FIRST event occurred and populate the variable with 1 and 0 otherwise. Also my actual data set has multiple years of data.

 

 

Have Want
PersonID YearMonth Logons Calls FirstLogon FirstCall
A 201701 0 5 0 1
A 201702 0 0 0 0
A 201703 0 0 0 0
A 201704 1 0 1 0
A 201705 5 1 0 0
A 201706 0 0 0 0
A 201707 0 0 0 0
A 201708 2 0 0 0
A 201709 1 0 0 0
A 201710 0 2 0 0
A 201711 2 0 0 0
A 201712 1 0 0 0
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input PersonID $	YearMonth Logons	Calls;
datalines;
A	201701	0	5
A	201702	0	0
A	201703	0	0
A	201704	1	0
A	201705	5	1
A	201706	0	0
A	201707	0	0
A	201708	2	0
A	201709	1	0
A	201710	0	2
A	201711	2	0
A	201712	1	0
;


data want;
set have;
by PersonID;
retain _temp1	_temp2  ;
if first.personid then do;_temp1=0;	_temp2=0;end;
if Logons and not(_temp1)   then do; _temp1=1;FirstLogon=1;end;else FirstLogon=0;
if calls and not(_temp2)   then do; _temp2=1;Firstcall=1;end;else firstcall=0;
drop _:;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
input PersonID $	YearMonth Logons	Calls;
datalines;
A	201701	0	5
A	201702	0	0
A	201703	0	0
A	201704	1	0
A	201705	5	1
A	201706	0	0
A	201707	0	0
A	201708	2	0
A	201709	1	0
A	201710	0	2
A	201711	2	0
A	201712	1	0
;


data want;
set have;
by PersonID;
retain _temp1	_temp2  ;
if first.personid then do;_temp1=0;	_temp2=0;end;
if Logons and not(_temp1)   then do; _temp1=1;FirstLogon=1;end;else FirstLogon=0;
if calls and not(_temp2)   then do; _temp2=1;Firstcall=1;end;else firstcall=0;
drop _:;
run;
mikemangini
Obsidian | Level 7

worked perfectly. Thank you for your help!

 

Mike

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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