I have a long syntax (1800 lines) and this one portion has been giving me trouble. I can't for the life of me figure out what I'm doing incorrectly.
It is supposed to take an existing file and narrow it down to just the variables listed in the /KEEP statement. Then every variable is renamed to a similar variable name, but "oldxxxx". Later my syntax matches the new file to this updated variable file and points out any changes in the values, giving a list of reasons in the recoded file.
Once the syntax reaches the first RENAME VARIABLES I get the following error:
RENAME VARIABLES Duplicate variable names from RENAME.
Thank you in advance!
First a couple of remarks: It would be better practice to save to a different file name. In your syntax the original file gets saved over and you can't go back... Also I recommend you follow #Andy W's advice regarding how to keep only the variables you need in your file.
Now, in the sample syntax you posted I see an error - possibly that's your problem:
RENAME VARIABLES (total_EMFASYS_award=oldgrant).
The new name is oldgrant instead or oldtotal_EMFASYS_award. Possibly further down you've got another command saying
RENAME VARIABLES (grant=oldgrant).
hence the double name.
To avoid such errors and shorten your syntax, you could use the following macro:
define renVars (!pos=!cmdend)
rename variables
!do !i !in (!1) !i = !concat("old",!i)
!doend .
!enddefine.
After running this macro definition you can run the macro by stating the macro name and the full list of variables you want renamed, like this:
renVars
Student_ID rl_highschoolgpa comb need qualitygrp NewUpfrontGrant meritgrant
targetcounty_housing housinggrant tuitiongrant athlete_recruit .
One thing to note about RENAME VARIABLES command - it also works like this:
RENAME VARIABLES (list_of_starting_variable_names = list_of_final_variable_names).
you would just need to provide the 2 names lists, and the renaming will be done in th eorder in which the names are provided (1st variable in list 1 gets renamed to the 1st variable in list 2,... n-th variable in list 1 into the n-th variable in list 2... and so on.
This should avoid the Duplicate Variable Names error you are getting, as all renames are done in one go. But would require you to alter the original syntax a bit, and is a bit harder to spot which variable gets renamed into which variable.
Related
I have a database with a lot of variables where the order of the variables is important. However, I want to sort my variables by type in between so that I can fill in the missing values by type. Before ordering them by type, I would like to save the order of the variables using Syntax so that I can return to this order after I have filled in the missing values. So the question is: How do I save a variable order using Syntax in SPSS?
I have tried using the “save current (pre-sorted) variable order” checkbox with the Paste command but that did not give me the Syntax code for saving the original order but only that of sorting the variables by type. Any help would be much appreciated.
You can use the following command to save the original variable order in a macro:
SPSSINC SELECT VARIABLES MACRONAME="!origlist" VARIABLES=all /options order=file.
After running this you can go ahead and change the order in the data. When you want to go back to the original order you can use this:
add files /file=* /keep=!origlist .
I Need to understand a very Long matlab file.
It is very tedious to put Breakpoints everywhere.
I wondered if there is an Option to track every possible variable at once ?
Something that would maybe store each variale in a text sheet and diaplays how they Change througout the code...
There are many many variables.
What I want to do is to create a scribt, where I can Input a list of variable names. The script then tracks those variable names within the program and exports them every time they Change.
Input: List of variables and programm Name (other script)
Content: Tracks variable in the Programm
Output: Table with tracked variables
Name_variable_1 |Value at line...|Value at line...|Value at line...
Name_variable_2 |Value at line...|Value at line...|Value at line...
.
.
.
Thanks.
You could maybe save the workspace periodically and then make a seperate MATLAB script that graphs the changes of the variables or writes out a text file for it?
I assume you're familiar with MATLAB, but just to be safe:
http://de.mathworks.com/help/matlab/ref/save.html
Just append the variable's contents to a text file or save the entire workspace and parse it later.
I frequently find myself examining deeply nested data in the variable explorer, e.g.:
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(4)
In order to be descriptive, the variable names are often long. I often want to use some of the data I'm looking at in Matlab expression, composed at the command line. So I end up typing the lengthy series of variable names and indexes. Autocompletion helps, but not much, especially since my variable names share many substrings.
It would be a lifesaver if I could copy into the clipboard the entire expression corresponding to the data being examined in the variable viewer. I haven't yet found a way to do this (the most obvious way being to right-click the tab for the data being examined). So I'm not sure if this functionality exists. Can anyone confirm or deny (hopefully the former) whether this functionality exists? If it does, how is it done?
As an example, suppose you had a class file myClass.m in the current working directory:
% myClass.m
%----------
classdef myClass
properties
structArray1
end % properties
end % class
Now suppose you issued the following commands:
objectName = myClass
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(1:3)=rand(1,3)
openvar('objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray')
You are now examining a slew of data within a deeply nested data structure. Normally, the data would have been the result of computation other than the rand statement above, and I would have browsed to it manually rather than using the openvar statement above. So I would not normally have readily available the text for the expression
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray
I have to manually type it in at the command line if I want to use it in a Matlab expression for further computation. It'd be so great if I could somehow point to the tab for that data in the variable explorer and somehow have the expression for the data copied to the clipboard. That way, I can paste it to the command line.
AFTERNOTE:
If there's no way to do this, then as an alternative to manually typing in the whole expression above, is there a way to access the corresponding data object (or a copy thereof) programmatically through the variable explorer window object? This assumes, of course, that the variable explorer is itself a data object as well, through which properties can be accessed. If so, maybe it has a property (perhaps deeply nested) that represents the expression for data in the tab that currently has the focus. If so, I can write a function to retrieve the corresponding data object.
I found that if I undock a tab from the Variables editor, I can select the variable name by double-clicking the variable name in the tab.
Sorry for the ambiguity in wording, but "tab" use to mean the protrusion in the data sheet for displaying the name of the data sheet. Nowadays, "tab" means the whole data sheet. In the first sentence above, I mean the protrusion, which unfortunately doesn't have a distinct name these days (at least none of which I'm aware).
After copying and pasting the variable name from the protrusion, the tab can be docked, which seems to put it back into its original place.
I'm using a simulationenvironment in matlab that's consisting of multiple scripts, functions and simulink models. Now I want to find out which of These created a specific variable in my Base-Workspace. Is there a way of finding this out?
One cannot trace back how a variable was created, but you may find the possible candidates that might create the variable.
If you know the name of the variable (let's say is 'my_var'), the use the 'Find files...' from the Edit menu (the usual key biding is [Ctrl]+[Shift]+[F]) to look into all files that containing the text my_var. Do not forget to configure the containing folder to include other paths than the current one, if you're calling some package/toolbox-level scripts.
I need to create a matlab mfile that will run another matlab file with default values given in a txt file. It's ment to be useful for testing programs, so that user may specify values in a txt files and instead of inputing values every time he starts the program, my script will give the program default values and user will only see the result.
My idea is to load tested file into a variable, change 'variable=input('...');' for variable = default_variable;, save it to tmp file, execute, and than delete tmp file. Is this going to do the job?
I have only two problems:
1) How to eliminate the problem of duplicated variable names - i mean this must work for all scripts, i don't know the names of variables used in tested script.
2) As I wrote before - is this going to work fine? Or maybe I missed a easier way to do it - for example maybe I don't have to create a tmp file?
I really need your help!
Thanks in advance!
If the person who has to edit the default values has access to Matlab, I would recommend saveing the values in a mat file and loading them when needed. Otherwise you could just write a smalls cript that contains the assignment to certain variables, but make sure to keep this small. For example:
maxRuns = 100;
clusters = 12;
So much for setting up the defaults. Regarding the process my main advice is to wrap the thing that you want to test into a function. This way variables used in the code to call the 'script' will not interfere as a function gets its own separate workspace. Check doc function if you are not familiar with them.