I need to calculate the percentile 85 and then save in a variable because I want to use it in many condition sentences like:
IF(variable>percentile85) a=0.
IF(variable2>percentile85) b=0.
IF(variable3>percentile85) c=0.
Is there a way to save a value into a variable and then use it?
use RANK command with Ntiles, then use the new variable created:
RANK VARIABLES=YourVar(A) /NTILES(100).
IF(NYourVar>=85) a=0.
EXECUTE.
Note that you can actually use Python in SPSS. The downloadable Programming and Data Management book has many examples. The SPSSINC TRANS extension command makes it particularly easy to do data transformations using Python code.
Related
How can I add a superscript to a variable, when I try to type it in to the Maxima Computer Algebra System?
So for example, I would like to have variables named U^(AC), U^(DC) where my intention is not to raise the variable to the power of something, but to have it as part of its name.
UPDATE, NEW ANSWER: Code to implement presuperscripts, presubscripts, postsuperscripts, and postsubscripts has been merged into Maxima. It is available now in the current version from Git, and it will be included in the next release of Maxima, which will be Maxima 5.44. See declare_index_properties in the online documentation (via ?).
OLD ANSWER: There isn't a built-in way to achieve that. That said, to some extent you can use A^B as a symbolic variable in some ways, depending on what you are trying to do. For example, given e:X*A^B + Y you can say solve(e, A^B) and it will return [A^B = -Y/X]. If you say more about exactly what you are trying to achieve, I might be able to give more specific advice.
A while ago I wrote some code to enable Maxima to treat indices of variables as subscripts as well as subscripts (as put the indices before as well as after the variable). I will dust off that code and write more about it here.
You can name it like that :
U^"AC"
U^"AC"*2=456; solve(%, U^"AC");
But it is a good idea to 'define' it before with something like :
UAC : U^"AC"; UAC *2=456; solve(%, UAC );
I have some proprietary implementation of lua, and all the variables exposed to me are in the form of 'ME.AV123' (for example). What is 'ME'? Is it a namespace? Is it a class? Is there a way to tell? Should I be able to do some sort of type(ME) (which does not seem to work)? In the documentation it says the keyword 'ME' is used to access the objects in the local database.
Follow-up, bonus question - Is there a way to get to all the variables in ME? I.e. - like the global variables use _G[varname], is there an equivalent way to do this for ME?
I apologize if I am not giving you enough. I am new to Lua, and I have relatively limited functionality through this .... thing.
Just to maybe put a finer point on it, and illustrate what I am actually trying to do:
I can interact with some set of variables, which are all in the documentation. All of them are name(addressed?) 'ME.varname'. So, to set 'AV120' to '1', I would say ME.AV120 = 1. I need to set some.. few dozen of these things, and would like a way to loop through all the variables, setting them as I go. I would think something like:
for i,j in pairs(mySettingsTable) do
ME[i] = j
end
Does this make sense?
From the Lua reference manual:
https://www.lua.org/manual/5.3/manual.html#2.1
The language supports this representation by providing a.name as
syntactic sugar for a["name"].
So ME.AV123 is the same as ME["AV123"].
It is just a more convenient form of indexing.
type() returns a string, in case you're wondering why the function does nothing on it's own. print(type(ME)) should work.
I am not used to SPSS so this question will sound stupid:
I need to change fragments of a cell in spss, exemple:
'1.28'
'2.69'
'3.57'
to
'a.28'
'b.69'
'c.57'
What's the best way to do it?
Tks.
This is assuming the variable you want to recode is called 'VarA', and that it is numeric.
This creates a copy of the variable, converts it to a string, and then uses those values to create a new version that is recoded.
RECODE VarA (ELSE = COPY) INTO VarA_String.
ALTER TYPE VarA_String(A8).
EXECUTE.
COMPUTE VarA_r=REPLACE(VarA_String,'1.','a.').
COMPUTE VarA_r=REPLACE(VarA_String,'2.','b.').
COMPUTE VarA_r=REPLACE(VarA_String,'3.','c.').
EXECUTE.
The syntax is a little different in SPSS Modeler and bear with me as I can only attach one image until I have a certain reputation on SO.
After you convert VarA into a string (which I called to_str) you can use the replace command to change part of the substring, ie:
to_string(VarA)
for the first Derive node, and:
replace('1.','a.',to_str)
for the second Derive node, this command replaces all occurrences of SUBSTRING1 with SUBSTRING2 in STRING and you will get the same result but in Modeler, see the sample stream here
Assuming that these are strings, see the replace function in COMPUTE. If there are just a few, though, just edit the cells in the Data Editor.
Frequently, PSPP/SPSS syntax documentation (example) suggests I must to pass a list of variables with /VARIABLES=var_list and this is not an optional subcommand.
But I have a lot of datasets to process. I would like to programmatically get a list of all variables in the active dataset, pass that to a procedure, and then generate a file from the procedure output.
I've tried /VARIABLES=* but that didn't work.
error: DESCRIPTIVES: Syntax error at `*': expecting variable name.
You can use display variables. or display dictionary. to generate a table of all variables and their attributes which could then be captured using OMS. However if you want to pass all variables to a function that expects a list you can use all, i.e. descriptives /variables= all..
/VARIABLES is often optional in procedures, but ALL stands for all the variables. If you need to refine by a particular measurement level, type or other metadata, try the SPSSINC SELECT VARIABLES extension command. This command applies various filters based on the metadata and creates a macro with the variables that pass. You can then use that in any context.
is there a way to use calculations made in matrix language (matrix-end matrix) as macro variables later in calculations?
Let say I calculate chi^2 and pvalue in matrix language and then I want to use them as my new macro variables for, let say, printing information about if the statistics is significant or not.
Of course I can use OMS to solve my problem but I want to find out if there is a possible way to get variables from matrix language to syntax later on.
You might want to look into Python programmability instead of macro. It is much more powerful and flexible. You can read about it in the books and articles section of the SPSS Community website (www.ibm.com/developerworks/spssdevcentral). The site also provides the materials for getting started with programmability.
MATRIX can write datasets, which Python can read and manipulate - and it can even generate macro values from them.
HTH,
Jon Peck