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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.