Hello!
I am looking to create some code that pulls only the newest SBSCR_NBR, SUB_FST_NM, and SUB_LST_NM based on the newest LOAD_DT (Date9. format). SBSCR_NBR should be unique, but sometimes people have multiple names in the system (i.e.: Jim/James, Bob/Robert for first name, and last names can change if maiden names change). Having multiple instances of SUB_FST_NM, and SUB_LST_NM included in this table causes duplicates in the data that I am joining to. Can someone help me figure this one out?
My current code is as follows:
CREATE TABLE subtable AS
SELECT DISTINCT SBSCR_NBR
,SUB_FST_NM
,SUB_LST_NM
,LOAD_DT
FROM MEMBERTBL
WHERE RCD in ("EM");
QUIT;
Thanks. I think a slight modification to the code from @PeterClemmensen is needed.
proc sql;
create table subtable as
select SBSCR_NBR
, SUB_FST_NM
, SUB_LST_NM
, LOAD_DT
from MEMBERTBL
group by sbscr_nbr
having max(LOAD_DT) = LOAD_DT;
;
quit;
Untested since I can't see your data. But I think you want something like this
proc sql;
create table subtable as
select SBSCR_NBR
, SUB_FST_NM
, SUB_LST_NM
, LOAD_DT
from MEMBERTBL
having max(LOAD_DT) = LOAD_DT;
;
quit;
I don't see where you have described the desired output. Newest load date ... according to what separation? Do you want newest load date by SBSCR_NBR? You don't say that. Or do you want newest load date by some combination of SUB_FST_NM and SUB_LST_NM? Or do you want something else?
Thanks. I think a slight modification to the code from @PeterClemmensen is needed.
proc sql;
create table subtable as
select SBSCR_NBR
, SUB_FST_NM
, SUB_LST_NM
, LOAD_DT
from MEMBERTBL
group by sbscr_nbr
having max(LOAD_DT) = LOAD_DT;
;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.