1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
*Input Programs are highly depend of the format of datafiles. I have assumed that the format given in your email is exact.
*I use the character in the 4th position of each line to differentiate the type of records.
*Thus RECORD TYPE 'E' is the first line for each case
*RECORD TYPE 'l' contains the number of links, etc.
*The records containing the links have a blank in the 4th column.
*The final file (the output of the syntax) contains one case per caseid, the number of links and the list of all links for that caseid.
 
*The syntax can be run as is and will demonstrate its operation using the inline data. To run the syntax on your data, 
*follow the instructions given below. Ray.

**** SYNTAX ***
NEW FILE.
*FILE TYPE MIXED FILE='nodes.txt' RECORD=REC_ID 4 (A).

**************************************.
* To read your external data file instead of the inline data: 
1) add a * at the beginning of the next command
2) remove the * at the beginning of the prior command
3) replace nodes.txt by the path and name of your data file
4) delete everything between BEGIN DATA and END DATA.
**************************************. 

FILE TYPE MIXED RECORD=REC_ID 4 (A).

RECORD TYPE 'E'.
DATA LIST FIXED  / caseid 27-34(A).
LEAVE caseid.

RECORD TYPE 'l'.
DATA LIST FIXED  / nb_links 1-2.

RECORD TYPE ' '.
DATA LIST FIXED  / node1 5-6 node2 11-12.
END FILE TYPE.

BEGIN DATA
PFNET D:\\SHARON\\PCKNOT\\DD\\M19A.PRX
16 nodes
19 links
1 minimum link weight
3 maximum link weight
links:
 node1 node2 Weight type
     1     2   1    x
     1    10   1    x
     2     5   1    x
     2     7   1    x
     2    16   1    x
     3    13   3    x
     4     9   2    x
     4    10   2    x
     4    16   2    x
     5     7   1    x
     5    11   2    x
     5    15   1    x
     6     8   3    x
     7    11   2    x
     8    12   2    x
     9    14   2    x
    11    15   2    x
    12    13   2    x
    13    14   2    x
PFNET D:\\SHARON\\PCKNOT\\DD\\M19B.PRX
16 nodes
15 links
1 minimum link weight
3 maximum link weight
links:
 node1 node2 Weight type
     1     2   1    x
     2    10   1    x
     3     5   1    x
     3     7   1    x
     3    16   1    x
     4    13   3    x
     5     9   2    x
     5    10   2    x
     6     7   1    x
     7     8   3    x
     8    11   2    x
     9    12   2    x
    10    14   2    x
    12    15   2    x
    13    14   2    x
END DATA.


DO IF $casenum=1.
COMPUTE nb=1.
ELSE.
COMPUTE nb=(caseid=lag(caseid))*lag(nb)+1.
END IF.

VECTOR nod1_(25F8.0) nod2_(25F8.0).
DO IF nb>2.
COMPUTE nod1_(nb-2)=node1.
COMPUTE nod2_(nb-2)=node2.
END IF.

*If the maximum number of links can exceeds 25, the replace all 25s below by the maximum applicable.
AGGREGATE
  /OUTFILE=*
  /BREAK=caseid
  /nb_links = MAX(nb_links) 
  /nod1_1 TO nod1_25= MAX(nod1_1 TO nod1_25) 
  /nod2_1 TO nod2_25= MAX(nod2_1 TO nod2_25).