I have the following observations ....
DATA INPUT;
DSNAME -
GPSP.BKUP.EXPIRED.TRANS.LOG.G3821V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3822V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3823V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3824V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3825V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3826V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3827V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0033V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0034V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0035V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0036V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0037V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0038V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00
I like to select (in this example) - only the following entries -
GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00
I tried the following code -
DATA WANTED;
SET INPUT;
BY DSNAME;
IF LAST.DSNAME;
RUN;
It does NOT work. Thank you.,
It's because your dsname is always unique, and therefore each by group contains only 1 observation.
I guess you would want this:
data input;
input dsname $50.;
dsname_short = substr(dsname,1,find(dsname,'.',-50)-1);
cards;
GPSP.BKUP.EXPIRED.TRANS.LOG.G3821V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3822V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3823V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3824V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3825V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3826V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3827V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0033V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0034V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0035V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0036V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0037V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0038V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00
;
run;
data want;
set input;
by dsname_short;
if last.dsname_short;
run;
proc print data=want noobs;
run;
Result:
dsname dsname_short GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00 GPSP.BKUP.EXPIRED.TRANS.LOG GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00 GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY
It's because your dsname is always unique, and therefore each by group contains only 1 observation.
I guess you would want this:
data input;
input dsname $50.;
dsname_short = substr(dsname,1,find(dsname,'.',-50)-1);
cards;
GPSP.BKUP.EXPIRED.TRANS.LOG.G3821V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3822V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3823V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3824V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3825V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3826V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3827V00
GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0033V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0034V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0035V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0036V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0037V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0038V00
GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00
;
run;
data want;
set input;
by dsname_short;
if last.dsname_short;
run;
proc print data=want noobs;
run;
Result:
dsname dsname_short GPSP.BKUP.EXPIRED.TRANS.LOG.G3828V00 GPSP.BKUP.EXPIRED.TRANS.LOG GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY.G0039V00 GPSP.BKUP.EXTR.CD.GPPFINTF.WR.MLY
Thank you. It works like a charm.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: