Name data file based on date read from data file
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 | Option Explicit 'Data must be in data editor before running script 'This finds the earliest date contained in variable date1 'then it saves the data file with the name RRDDMMYYYY where DD,MM and YYYY 'are the day, month and year of the earliest date found in date1 'Author=? Sub Main Dim objDataDoc As ISpssDataDoc Dim dateval As Variant Dim NOC As Integer Dim i As Integer Dim min As Date Dim date1 As Date Dim strCommand As String Dim strtest As String Set objDataDoc = objSpssApp.Documents.GetDataDoc (0) NOC = objDataDoc.GetNumberOfCases dateval = objDataDoc.GetTextData ("date1", "date1", 1, NOC) min = dateval (0,1) For i = 1 To NOC - 1 date1 = dateval (0, i) If date1 < min Then min = date1 Next i If Day(min)<10 Then strtest="'c:\\temp\\RR0"+CStr(Day(min)*1000000+Month(min)*10000+Year(min))+".sav'" Else strtest="'c:\\temp\\RR"+CStr(Day(min)*1000000+Month(min)*10000+Year(min))+".sav'" End If strCommand="save outfile="+strtest+"."+vbCrLf objSpssApp.ExecuteCommands strCommand, False End Sub |
Related pages
...