Hi i have a data format as below and all are characters
id_1 | id_2 | year_month |
---|---|---|
C123 | 97813 | 201209 |
C123 | 77980 | 201212 |
C234 | 56432 | 201212 |
C345 | 76556 | 201201 |
C345 | 97813 | 201209 |
C456 | 56432 | 201212 |
Want row only has max of year_month example:
id_1 | id_2 | year_month |
---|---|---|
c123 | 77980 | 201212 |
c234 | 56432 | 201212 |
c345 | 97813 | 201209 |
c456 | 56432 | 201212 |
The following should work:
proc sql;
create table want as
select *
from have
group by id_1
having year_month=max(year_month)
;
quit;
The following should work:
proc sql;
create table want as
select *
from have
group by id_1
having year_month=max(year_month)
;
quit;
You can also try this approach
PROC SQL;
CREATE TABLE WANT AS
SELECT t1.id_1,
t2.id_2,
t2.year_month
FROM (SELECT id_1,
/* max_year */
(MAX(INPUT(year_month,6.))) AS max_year_month
FROM HAVE
GROUP BY id_1) t1, (SELECT id_1,
id_2,
year_month,
/* year_month numeric */
(INPUT(year_month,6.)) AS year_month_num
FROM HAVE) t2
WHERE (t1.id_1 = t2.id_1 AND t1.max_year_month = t2.year_month_num);
QUIT;
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.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.