Hi,
i have this table:
KEY | CAU |
2335083090018500 | M88 |
33111356428352800 | M88 |
33111275803210300 | M88 |
33111381165566500 | M88 |
33111708996242600 | M88 |
33111708996242600 | M90 |
2214196DL51H86501 | M88 |
2214196DL51H86501 | M90 |
33111230975677500 | M88 |
33111230975677500 | M90 |
3311359190969000 | M88 |
3311359190969000 | M90 |
33111380983028300 | M88 |
33111380983028300 | M90 |
503440K7QD3L18858 | M88 |
22158083090018500 | M88 |
503440K7QD3L18858 | M90 |
2215083090018500 | M90 |
33111208999140500 | M88 |
I want create a new column (RESULT) with value "YES" when the value of column key is equal to previous value and the value of column CAU is equal at 'M90' and previous value is equal to 'M88', this is example:
KEY | CAU | RESULT |
2335083090018500 | M88 | |
33111356428352800 | M88 | |
33111275803210300 | M88 | |
33111381165566500 | M88 | |
33111708996242600 | M88 | |
33111708996242600 | M90 | YES |
2214196DL51H86501 | M88 | |
2214196DL51H86501 | M90 | YES |
33111230975677500 | M88 | |
33111230975677500 | M90 | YES |
3311359190969000 | M88 | |
3311359190969000 | M90 | YES |
33111380983028300 | M88 | |
33111380983028300 | M90 | YES |
503440K7QD3L18858 | M88 | |
22158083090018500 | M88 | |
503440K7QD3L18858 | M90 | |
2215083090018500 | M90 | |
33111208999140500 | M88 |
Can someone give me a help to create a data step with retain function?
Thanks!!!!
You could use RETAIN but this is what the LAG function which looks at previous values.
data want;
set have;
Lkey = lag(key);
LCAU = lag(CAU);
if Lkey=key and CAU='M90' and LCau='M88' then Result='YES';
drop Lkey Lcau;
run;
Use retain to create two new variables, like key_ret and cau_ret.
Assign them the current observation values last in the data step, after any conditional assignments.
You could use RETAIN but this is what the LAG function which looks at previous values.
data want;
set have;
Lkey = lag(key);
LCAU = lag(CAU);
if Lkey=key and CAU='M90' and LCau='M88' then Result='YES';
drop Lkey Lcau;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: