compute date fields base on file path

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Posts: 52
Joined: Fri Mar 04, 2011 9:42 pm

compute date fields base on file path

Postby 0101 » Tue Jul 10, 2012 10:34 pm

I have a script that assigns the path and name of a selected file to a macro, !Path, which is then opened with GET FILE = !Path.

The path and file always look something like this:

C:\DATA\Revenue\2009A\Revenue09A 23_785.sav
C:\DATA\Revenue\2009B\Revenue09B 5_75.sav
C:\DATA\Revenue\2010A\Revenue10A 43_095.sav

The path always includes a year and a letter (A or B). The year refers to the federal fiscal year, and the letter refers to the first half of the FFY (A = Oct 1 - Mar 31) or the last half (B = Apr 1 - Sept 30). I need to compute Begin and End dates based on the year and letter (the A or B) in the path.

So an 09A file, which spans Oct 1, 08 - Mar 31, 09, should yield this:

Code: Select all

compute BeginDate=yrmoda(2008,10,01).
compute EndDate=yrmoda(2009,03,31).
An 09B file, which spans Apr 1, 09 - Sep 30, 09, should yield this:

Code: Select all

compute BeginDate=yrmoda(2009,04,01).
compute EndDate=yrmoda(2009,09,30).

Any suggestions about how to extract the year and letter from the file path, and use that information to compute the appropriate Begin and EndDates?

This is the script I use to extract the path:

Code: Select all

Sub Main
   Dim strCmd As String
   Dim strPath As String
   strPath =GetFilePath(, "sav", "C:\DATA\Revenue\","Please select the 6-month file", 0)
   If strPath = "" Then Exit Sub 'User clicked Cancel
	strCmd="DEFINE !Path()'" & strPath & "'!ENDDEFINE,"
    Debug.Print strCmd
	objSpssApp.ExecuteCommands strCmd, False
End Sub

Who is online

Users browsing this forum: No registered users and 1 guest