I need help with the below code snippet.
data A dup;
set B; /* Sorted dataset by id update_dt updt_code*/
by id update_dt updt_code;
if first.id and last.updt_code then output A;
else output dup;
run;
Data B:
id Update_dt updt_code
123 14/02/2017 3
123 14/02/2017 3
123 14/02/2017 6
Required Data A:
id Update_dt updt_code
123 14/02/2017 3
123 14/02/2017 6
The most efficient way to achieve your intended (as I guess) result is this IMO:
proc sort
data=b
out=a
nodupkey
dupout=dup
;
by id update_dt updt_code;
run;
The most efficient way to achieve your intended (as I guess) result is this IMO:
proc sort
data=b
out=a
nodupkey
dupout=dup
;
by id update_dt updt_code;
run;
by filtering on "first.id" you can only get at most the first of your three recrods. But the last.updt_code dummy is not simultaneously true in your data. I think you want;
data a dup;
set b;
by id update_dt updt_code;
if first.updt_code=1 and last.updt_code=1 then output a;
else output dup;
run;
Remember, if you have multiple BYvars, whenever a given by var is in first. or last. condition, all by vars to its right will also be set to first. or last. condition - even if their values don't change throughout the entire dataset. By-variable dummies are hierarchical.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.