Greetings,
I'm modifying this code to attempt to obtain the following output. Basically I have a first_time_email_seen_with_user field below, and I want to to return a blank for this value.
ID Date email_address
josh 1/1/2015 josh1@gmail.com
josh 1/2/2015 josh2@yahoo.com
josh 1/3/2015 josh3@yahoo.com
mary 1/4/2015 mary123@aol.com
mary 1/5/2015 mars@blah.com
josh 1/6/2015 josh1@gmail.com
josh 1/7/2015 josh2@yahoo.com
josh 1/8/2015 josh3@yahoo.com
mary 1/9/2015 mary123@aol.com
mary 1/10/2015 mars@blah.com
ID Date email_address distinct_emails_for_user first_time_email_seen_with_user
josh 1/1/2015 josh1@gmail.com 1 .
josh 1/2/2015 josh2@yahoo.com 2 YES
josh 1/3/2015 josh3@yahoo.com 3 YES
mary 1/4/2015 mary123@aol.com 1 .
mary 1/5/2015 mars@blah.com 2 YES
josh 1/6/2015 josh1@gmail.com 3 NO
josh 1/7/2015 josh2@yahoo.com 3 NO
josh 1/8/2015 josh3@yahoo.com 3 NO
mary 1/9/2015 mary123@aol.com 2 NO
mary 1/10/2015 mars@blah.com 2 NO
So far ksharp has assisted me with this portion of the code. I know that there's something that we have to add with first.id -- that will allow me to modify the first instance of the record occuring, but I'm unsure of how where to implement this.
data want;
if _n_ eq 1 then do;
declare hash hh();
hh.definekey('id');
hh.definedata('count');
hh.definedone();
declare hash h();
h.definekey('id','email_address');
h.definedone();
end;
set have;
length flag $ 8;
if h.find()=0 then do;
hh.find();flag='NO';
end;
else do;
flag='YES';
if hh.find()=0 then count+1;
else count=1;
h.replace();hh.replace();
end;
run;
data want4 (drop=flag);
set want2;
/*by id;*/
first_time_appear=flag;
if first.id then first_app_in_acct =1;
run;
proc print;quit;
I added an extra field at the end that created a seperate flag for the first record by account. I simply use that to exclude those values when I am tabulating the query.
data want4 (drop=flag);
set want2;
/*by id;*/
first_time_appear=flag;
if first.id then first_app_in_acct =1;
run;
proc print;quit;
I added an extra field at the end that created a seperate flag for the first record by account. I simply use that to exclude those values when I am tabulating the query.
Overwrite it at the end of code.
data want;
if _n_ eq 1 then do;
declare hash hh();
hh.definekey('id');
hh.definedata('count');
hh.definedone();
declare hash h();
h.definekey('id','email_address');
h.definedone();
end;
set have;
length flag $ 8;
if h.find()=0 then do;
hh.find();flag='NO';
end;
else do;
flag='YES';
if hh.find()=0 then count+1;
else count=1;
h.replace();hh.replace();
end;
if count=1 then flag=' ';
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.