How to use a variabe value to name a file using SPSS syntax? - spss

I have a data set with 100+ variables for each of many people.
I have two variables for the person's name: lastname and firstname.
How can I create an output file using the names (i.e., the values of the variables lastname and firstname)?
I would like to do a split file by lastname firstname and export the data for each person into a text file that uses the person's name as the file name.
Below is what my spss command file is doing now. How can I get the command file to spit out separate files for each person?
SORT CASES BY lastname firstname .
SPLIT FILE BY lastname firstname .
PRINT / " ".
PRINT /
"===================================================================".
PRINT / "Report of Selected Responses from the".
PRINT / "Survey Form Document".
Print /"Responses for Candidate: " .
Print / firstname.
Print / lastname.
PRINT /
"===================================================================".
DO IF (Q1.5month EQ "" OR sysmis(q1.5day) OR sysmis(q1.5year) ).
Print
/ "1.5. Some or all of date of birth left blank".
END IF.
[More such print statements.]
EXECUTE.
SPLIT FILE OFF.

First create an empry string variable and populate it:
String firstname_lastname (A100).
Compute firstname_lastname=concat(rtrim(firstname),"_",rtrim(lastname)).
EXECUTE.
Then go to Data menu, Split into files, select your new firstname_lastname variable as the split variable, and.under options select "value labels". Pick a folder and you are done. Maybe click paste, to have everything in syntax 😉

Related

How to take a named path string stored in Excel's name manager and open a file using it. The stored string contains the entire file string

The first routine grabs the filename string as the user locates a file which was exported from Quickbooks
The second routine writes that name into the name manager as a string under the name
"PathToEmployeeWithholding"
The third routine attempts to open the file using the name stored in the name manager
I have verified in the name manager that the name and correct path string is there, but I have not been successful in using that name to retrieve the file for reading.
The current code returns a 1004 error, but debug.print does give the correct path, pasting the string in the windows run box opens the spreadsheet, and so does a static statement with the path.
Thanks in advance for your help
lang-VB
'HouseKeepingCODE Module
Sub GetPath()
'This sub gets the path to a File defined by the user within the routine
'It then calls another sub that applies that path to a name in the worksheet.
' Before calling this routine, The name should first be searched for, and then verified, then opportunity given to change the name.
Dim MyPath As String 'String to hold the path to an excel spreadsheet exported from quickbooks
Dim NameToChange As String 'String that holds the name manager name to store the path under
Dim NameComment As String 'Comment to identify the name in the name manager
NameToChange = "PathToEmployeeWithholding"
NameComment = "This Name contains the Path to the 'Employee Withholding' worksheet exported from quickbooks using VBA"
With Application.FileDialog(msoFileDialogFilePicker)
If .Show <> 0 Then
MyPath = .SelectedItems(1)
End If
End With
'Debug.Print PathToWithholding
'This routine should be modified
'It should simply get a path to a file,
'And return that path to the calling subroutine
'The calling subroutine should then add comment and call the changevalueofname subroutine
Call ChangeValueOfName(NameToChange, MyPath, NameComment) 'this routine stores the retrieved text string in the name manager
End Sub
Sub ChangeValueOfName(NameToChange As String, NewNameValue As String, Comment As String)
'
' ChangeValueOfNameMagagerName Macro
' Changes the Value of a defined name in the Name Manager
'This should be used to change the name.
'
'Once the file is selected data needs to be imported to an array, and the
'Employee name values need to be checked against the worksheets in the workbook and against the recap sheet
'If changes are needed, it needs to write them into the workbook, including changing recap sheet and adding
'worksheets for any new employees
'
'
'
'
With ActiveWorkbook.Names(NameToChange)
.Name = NameToChange
.RefersTo = NewNameValue
.Comment = Comment
End With
End Sub
'****problem subroutine below***
Sub UpdateEmployeewithholding()
'This sub will clean employee withholding as it is exported from quickbooks and then read the file into this workbook
'The path is already stored in the names manager
'This routine needs to integrate changevalueofname and getpath. They should update before executing the balance of this routine
Dim MyWorkBook As Workbook
Dim MyPath As Variant 'Contains path to employee withholding spreadsheet as exported from quickbooks. This sheet is to be modified for reading, but not saved
Dim MyRange As Range 'Contains a defined range after setting it so
Dim whichrow As Variant 'Marks the starting point for routines that find and delete blanks as well as those that define range values and scan them into an array
Dim Direction As Variant 'Defines whether we are progressing over "Rows" or "Columns"
Dim ArrayWidth As Range 'Holds the top row addresses of the array
Dim ArrayHeight As Range 'Holds the left column addresses of the array
Dim MyArray As Variant 'Holds the array to transfer to this spreadsheet
Dim Width As Long 'Holds the array width to prevent loosing it when the original spreadsheet closes
Dim Height As Long 'Holds the array height to prevent loosing it when the original spreadsheet closes
whichrow = 1 'We are starting in cell A! or R1C1
Direction = "Rows"
'******************************************************************************************************
'***INSERT Code that will read the string value stored in the name manager Name "PathToEmployeeWithholding" into the variable "MyPath"
' and eliminate the hard coded path from the routine
' STILL MISSING
'*****************************************************************************************************
'Setting MyPath to the fixed path to employee withholding until we can get the routine to 'open the workbook from a varialbe
'stored in the name manager
MyPath = ThisWorkbook.Names("PathToEmployeeWithholding")
'ActiveWorkbook.Names (PathToEmployeeWithholding)
Debug.Print MyPath 'This works
Set MyWorkBook = Workbooks.Open(MyPath) '***Problem line returns 1004 stored-path could
'not be found
Debug.Print ActiveWorkbook.Name
'**** The immediate statement below worked ***
debug.Print thisworkbook.Names("PathToEmployeeWithholding")="D:\redacted\Employee Withholding .xlsx"
'***Code below to extract data from workbook opened above
The problem was in the fact that pulling the name back from name manager always added an = sign plus open and close quotes for delimiters. .eg
="string\text"
The solution was to strip the delimiters using the mid function
Sub UpdateEmployeewithholding()
'This sub will clean employee withholding as it is exported from quickbooks and then read the file into this workbook
'The path is already stored in the names manager
'This routine needs to integrate changevalueofname and getpath. They should update before executing the balance of this routine
Dim MyWorkBook As Workbook
Dim MyPath As String 'Contains path to employee withholding spreadsheet as exported from quickbooks. This sheet is to be modified for reading, but not saved
Dim MyRange As Range 'Contains a defined range after setting it so
Dim whichrow As Variant 'Marks the starting point for routines that find and delete blanks as well as those that define range values and scan them into an array
Dim Direction As Variant 'Defines whether we are progressing over "Rows" or "Columns"
Dim ArrayWidth As Range 'Holds the top row addresses of the array
Dim ArrayHeight As Range 'Holds the left column addresses of the array
Dim MyArray As Variant 'Holds the array to transfer to this spreadsheet
Dim Width As Long 'Holds the array width to prevent loosing it when the original spreadsheet closes
Dim Height As Long 'Holds the array height to prevent loosing it when the original spreadsheet closes
Dim StrLength As Long
whichrow = 1 'We are starting in cell A! or R1C1
Direction = "Rows"
MyPath = ThisWorkbook.Names("PathToEmployeeWithholding") 'get string from name manager
Debug.Print MyPath 'As stored in name manager the name always returns and = sign plus open and close quotes
StrLength = Len(MyPath) 'In order to get the workbook to open programatically these must be stripped
MyPath = Mid(MyPath, 3, StrLength - 3) 'The mid statement strips these delimiters off, leaving just the text
Debug.Print MyPath
Set MyWorkBook = Workbooks.Open(MyPath)
Debug.Print ActiveWorkbook.Name
'Stuff below gets data from opened workbook

Change this string - adding a space rather than dash

I have a script which basically changes a characters name and rank if the command CharRankPromote is used. Initially, the automatic name given to the player would be something like TEXT-RANK-TEXT (or something or other), but recent changes in my mind resulted in the need to make a new system being just: RANK NAME. However, the current code does not recognize this new name format, would there be an easy fix? This is the code in question:
for index, rank in next, targetRanks do
if (string.find(name, "[%D+]" .. rank .. "[%D+]")) then
if (newRank == index) then
return "#cRankSameRank", name, rank
end
The string (name, "[%D+]" .. rank .. "[%D+]") would promote someone with the same TEXT-RANK.TEXT:TEST, as it could identify the rank in the name. I'd like to change it so it could identify the rank in the format "RANK NAME," with a space in between (with the string only focusing on the word at the front.

field a colums with the substring of the namefile in DataFlow

I want to field a colums name ManagingCountryCode with the name of File , this colums existe just in my Output (BD)
I've try to do a substring like that but always wrong!
I chose an option to store the fileName in a colums
[
like i say, i store the filesName in filenamecolum which is an option in (SourceOption) after that i did'nt get the error below(in picture) because he can define what is 'fileName' , after that i add mapping simple and i mapp the new colums with the others in output file.

How to compare and verify user input with a csv file columns data?

I am trying to get answer for the last few weeks. I want to give a textfield to users in the app and ask them to enter a id number and this number will be checked with the uploaded csv file columns. If it matches then display an alert saying that its found a match or else it doesn't.
A csv file is basically a normal file in which items are separated by commas.
For example:
id,name,email
1,Joe,joe#d.com
2,Pat,pat#d.com
To get the list of IDs stored in this csv files, simply loop through the lines, and grab the first item after splitting the string (use comma to split)
id = line.split(",").get(0); // first element ** Note this depends on what language you're using
Now, add this id to a collection of ids you are storing, like in a list.
IDs.add(id);
When you take the user input, all you need to do is to check if the id is in your list of ids.
if (IDs.contains(userId)) { print "Found"; }

Getting String Value when delimiter exists vb.net

I am working on finishing up a mvc 3 vb.net app... I have to parse about 2000 entries in a database and get the string value to the right of a " : " delimiter from one of the columns... Everything to the left I am not worried about but I need the value that is to the right of the colon for that item.. I have more issues involving needing to select string characters to the right or left of a delimiter... But if someone can show me how to achieve the above I can figure out the rest from there... Thanks again...
a example of the string is Jackson Smokehouse Fish Food:John Jacob JinggleHimer Schmit
I would want to eliminate the first part of the string or just select the second part and put it in a variable for later processing...
You could use string.Split(':') which will split your string into a string array. so you can just grab the string to the right. My VB is rusty:
Dim stringToRight as String
stringToRight = databaseString.Split("1"c)(1)
There are probably better ways, but this is straight forward.

Resources