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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3124 views
  • 0 likes
  • 2 in conversation