Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Creating Volume sequence numbers for Volume records - SAS

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1456
Location: Azeroth

PostPosted: Mon Jul 09, 2012 5:17 pm    Post subject: Creating Volume sequence numbers for Volume records - SAS
Reply with quote

Hi,
I have a SAS dataset which looks like,
Code:
DSN     VOLSER    NEXTVOL
                         
AAAA    V0002      V0003
AAAA    V0001      V0002
AAAA    V0004           
AAAA    V0003      V0004
BBBB    A0001           
BBBB    A0004      A0003
BBBB    A0003      A0002
BBBB    A0002      A0001
BBBB    A0005      A0004
CCCC    K0001           
DDDD    J000B      J000C
DDDD    J000C           
DDDD    J000Z      J000B
The requirement is to create a variable VOLSEQ which is volume sequence number.

Output required:
Code:
DSN     VOLSER    NEXTVOL    VOLSEQ
                                   
AAAA    V0001      V0002        1 
AAAA    V0002      V0003        2 
AAAA    V0003      V0004        3 
AAAA    V0004                   4 
BBBB    A0005      A0004        1 
BBBB    A0004      A0003        2 
BBBB    A0003      A0002        3 
BBBB    A0002      A0001        4 
BBBB    A0001                   5 
CCCC    K0001                   1 
DDDD    J000Z      J000B        1 
DDDD    J000B      J000C        2 
DDDD    J000C                   3 

The logic is,
For DSN = AAA, V0004 does not have NEXTVOL, so it is the last VOLSER in the sequence(VOLSEQ=4).
Next, the observation
AAAA V0003 V0004
has V0004 as NEXTVOL, so it is the last but first VOLSER in sequence(VOLSEQ=3).

Next, the observation
AAAA V0002 V0003
has V0003 as NEXTVOL, so its VOLSEQ=2 and so on..

Could you please let me know how this could be done.
Thanks & Regards,
Back to top
View user's profile Send private message

vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1456
Location: Azeroth

PostPosted: Mon Jul 09, 2012 5:24 pm    Post subject:
Reply with quote

I have tried a code to create the VOLSEQS but it makes a lot of passes through the same dataset(more than 4 times for sure),which makes it very ineffecient for large number of datasets.
So was looking for a simpler logic to achieve the same.

Code:
LIBNAME XX 'WELLS.SAS.DB1';                                             
DATA DSNVOLS;                                                           
  INFILE 'WELLS.SORTIN' MISSOVER;                                       
  INPUT DSN $4. VOLSER $ NEXTVOL $;                                     
RUN;                                                                   
                                                                       
PROC SQL NOPRINT;                                                       
  CREATE TABLE XX.DSNVOLS AS         /* CREATE SUBTOTALS FOR EACH DSN */
  SELECT *,COUNT(*) AS VOLCOUNT FROM DSNVOLS                           
  GROUP BY DSN;                                                         
  SELECT COUNT(DISTINCT DSN) INTO :DSNCOUNT FROM XX.DSNVOLS;           
QUIT;                                                                   
                                                                       
DATA VOLSEQS;                                                           
RETAIN VOLCOUNT PROCESSED 0;                                           
KEEP DSN VOLSER NEXTVOL VOLSEQ;                                         
DO M = 1 TO &DSNCOUNT.;                 /* DO FOR ALL INDIVIDUAL DSNS */
  PTR = PROCESSED + 1;                                                 
  SET XX.DSNVOLS POINT = PTR;                                           
  DO I = PTR TO PTR+VOLCOUNT-1;    /* THIS DO LOOP LOOKS FOR DSN WITH */
    SET XX.DSNVOLS POINT = I;      /* NEXTVOL = ' ' I.E. LAST VOLSER  */
    IF NEXTVOL = ' ' THEN DO;                                           
      VOLSEQ = VOLCOUNT;                                               
      STORE_VOL = VOLSER;                                               
      OUTPUT;                                                           
    END;                                                               
  END;                                                                 
  IF VOLCOUNT > 1 THEN DO;                                             
    DO J = 1 TO VOLCOUNT - 1;      /* THIS DO LOOP TAKES LAST VOLSER  */
      DO I = PTR TO PTR+VOLCOUNT-1;/* AND TRAVERSES OTHER VOLSERS     */
        SET XX.DSNVOLS POINT = I;  /* BASED ON NEXTVOL VARIABLE       */
        IF NEXTVOL = STORE_VOL THEN DO;                                 
          VOLSEQ = VOLSEQ - 1;                                         
          STORE_VOL = VOLSER;                                           
          OUTPUT;                                                       
        END;                                                           
      END;                                                             
    END;                                                               
  END;                                                                 
  PROCESSED = PROCESSED + VOLCOUNT;    /* KEEP TRACK OF PROCESSED OBS */
END;                                                                   
STOP;                                                                   
RUN;                                                                   
PROC SORT DATA = VOLSEQS ; BY DSN VOLSEQ; RUN;                         
PROC PRINT DATA = VOLSEQS; RUN;                                         
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2012 7:22 pm    Post subject:
Reply with quote

Hello,

Is there some reason this must be done with SAS?

It appears to be something Sort could do rather efficiently once the SAS input is placed in a sequential file ?
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1456
Location: Azeroth

PostPosted: Mon Jul 09, 2012 8:00 pm    Post subject:
Reply with quote

Hi D,
There is no restriction to which programming language this has to be done.

I think I am limiting my chances of getting an answer by mentioning SAS on the title. I would post a topic on DFSORT with the same requirement.
Kindly delete/close/leave this thread as it limits responses.

Regards,
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2012 8:41 pm    Post subject: Reply to: Creating Volume sequence numbers for Volume record
Reply with quote

Hi Vasanth,

Per your request, i'll lock this topic.

d
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Storing huge volume of data, compare ... Pradeep K M All Other Mainframe Topics 3 Mon Jan 16, 2017 5:08 pm
No new posts Incorrect output when trying to add n... monica1 PL/I & Assembler 10 Fri Jan 13, 2017 5:02 pm
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us