Flip command and string vars

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Flip command and string vars

Maguin, Eugene

Given a dataset of only string vars of the same dimension, e.g., a5, I’m curious as to why the Flip command returns sysmis for the rearranged dataset. I understand that this is a very specific situation and maybe that’s a good enough reason. And I understand why flip won’t work for a mixed dataset of either strings and numeric or strings of varying dimensions.

Gene Maguin

Reply | Threaded
Open this post in threaded view
|

Re: Flip command and string vars

Albert-Jan Roskam
It's documented by I have no idea why it behaves this way. In R you can use t(), so with a string-only dataset you can do:

begin program r.
cases = spssdata.GetCaseCount()
dta <- as.data.frame(t(spssdata.GetDataFromSPSS()))
varName <- paste("v", 1:cases, sep="")
varLabel <- rep("", cases)
varType <- rep(8, cases)  # assume only A8 vars
varFormat <- rep("A8", cases)
varMeasurementLevel <- rep("nominal", cases)
dict <- as.data.frame(t(data.frame(varName, varLabel, varType, varFormat, varMeasurementLevel)))
rownames(dict)  <- c("varName", "varLabel", "varType", "varFormat", "varMeasurementLevel")
names(dict) <- varName
spssdictionary.SetDictionaryToSPSS("transposed", dict)
spssdata.SetDataToSPSS("transposed", dta)
spssdictionary.EndDataStep()
end program.

Regards,

Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--------------------------------------------
On Tue, 11/19/13, Maguin, Eugene <[hidden email]> wrote:

 Subject: [SPSSX-L] Flip command and string vars
 To: [hidden email]
 Date: Tuesday, November 19, 2013, 4:28 PM









 Given a dataset of only
 string vars of the same dimension, e.g., a5, I’m
 curious as to why the Flip command returns sysmis for the
 rearranged dataset. I understand that this is a very
 specific situation and maybe that’s a good enough
 reason.
  And I understand why flip won’t work for a mixed
 dataset of either strings and numeric or strings of varying
 dimensions.

 Gene Maguin

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Flip command and string vars

David Marso
Administrator
In reply to this post by Maguin, Eugene
In all likelihood because FLIP is a brain-dead procedure and all the smart people were on vacation when they had the design meetings (FLIP is certainly pre 1990).  
Hint Gene:  Both VARSTOCASES and CASESTOVARS respect strings.
Furthermore they can use mixed length strings (setting the result to maximum).
In response to many angry callers and faxes, I created a 'workaround' in the early 90's using XSAVE in a loop followed by a VECTOR/AGGREGATE combo.  IIRC it was a pain because VECTOR also requires same size strings. To make it flexible required building a new set of variables with a known max-size and tossing those into the XSAVE loop.
That is now happily long obsolete since VARSTOCASES and CASESTOVARS (circa 2000 or so).  

DATA LIST FREE / a b (2A1) c d z (3A6).
BEGIN DATA
a b c d z
z d c b a
END DATA.

VARSTOCASES /ID=id /MAKE stack FROM a TO z /INDEX=oldvar(stack) .
ALTER TYPE  id (a10).
COMPUTE id=CONCAT("Case_",LTRIM(id)).
SORT CASES BY oldvar id.
CASESTOVARS /ID=oldvar/INDEX=id /GROUPBY=VARIABLE.

Maguin, Eugene wrote
Given a dataset of only string vars of the same dimension, e.g., a5, I'm curious as to why the Flip command returns sysmis for the rearranged dataset. I understand that this is a very specific situation and maybe that's a good enough reason. And I understand why flip won't work for a mixed dataset of either strings and numeric or strings of varying dimensions.
Gene Maguin
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Flip command and string vars

David Marso
Administrator
In reply to this post by Albert-Jan Roskam

Where is my sharpened spoon ;-)

Albert-Jan Roskam wrote
It's documented by I have no idea why it behaves this way. In R you can use t(), so with a string-only dataset you can do:

begin program r.
cases = spssdata.GetCaseCount()
dta <- as.data.frame(t(spssdata.GetDataFromSPSS()))
varName <- paste("v", 1:cases, sep="")
varLabel <- rep("", cases)
varType <- rep(8, cases)  # assume only A8 vars
varFormat <- rep("A8", cases)
varMeasurementLevel <- rep("nominal", cases)
dict <- as.data.frame(t(data.frame(varName, varLabel, varType, varFormat, varMeasurementLevel)))
rownames(dict)  <- c("varName", "varLabel", "varType", "varFormat", "varMeasurementLevel")
names(dict) <- varName
spssdictionary.SetDictionaryToSPSS("transposed", dict)
spssdata.SetDataToSPSS("transposed", dta)
spssdictionary.EndDataStep()
end program.

Regards,

Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--------------------------------------------
On Tue, 11/19/13, Maguin, Eugene <[hidden email]> wrote:

 Subject: [SPSSX-L] Flip command and string vars
 To: [hidden email]
 Date: Tuesday, November 19, 2013, 4:28 PM









 Given a dataset of only
 string vars of the same dimension, e.g., a5, I’m
 curious as to why the Flip command returns sysmis for the
 rearranged dataset. I understand that this is a very
 specific situation and maybe that’s a good enough
 reason.
  And I understand why flip won’t work for a mixed
 dataset of either strings and numeric or strings of varying
 dimensions.

 Gene Maguin

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"