Selecting the highest GDG in a dataset name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Selecting the highest GDG in a dataset name

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.,


Accepted Solutions
Solution
4 weeks ago
Super User
Posts: 8,590

Re: Selecting the highest GDG in a dataset name

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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
4 weeks ago
Super User
Posts: 8,590

Re: Selecting the highest GDG in a dataset name

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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 15

Re: Selecting the highest GDG in a dataset name

Posted in reply to KurtBremser

Thank you.  It works like a charm.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 94 views
  • 0 likes
  • 2 in conversation