Transpose & Restructure Help Please

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

Transpose & Restructure Help Please

DKUKEC
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Bruce Weaver
Administrator
How about this?

WEIGHT by Arrests.
crosstabs year by Offense.
WEIGHT off.

Stick an appropriate OMS command in front of that to write the table out to a new dataset.  


DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Transpose & Restructure Help Please

Marhefka, Stephanie

Hello. I will be out of the office  until Thursday, December 27, 2012. I will do my best to respond to you upon my return. 

Happy Holidays!

 

Stephanie L. Marhefka, Ph.D.

 

Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Bruce Weaver
Administrator
In reply to this post by Bruce Weaver
I just noticed that you also wanted Agency in your reformatted data.  So it's a bit complicated than I suggested.  I'm not sure if you can have multiple agencies within the same year -- your abbreviated example doesn't show that.  But here's a fairly general approach that might work for you.

new file.
dataset close all.

data list list / ID(f2.0) Year(f4.0) Agency(f2.0) OffenseStr(A10) Arrests(f5.0).
begin data
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268
5 1999 3 Arson 34
6 1998 4 Homicide 11
7 1998 4 Robbery 118
end data.
dataset name raw.

* OMS.
DATASET DECLARE  Xtab.
OMS
  /SELECT TABLES
  /IF COMMANDS=['Crosstabs'] SUBTYPES=['Crosstabulation']
  /DESTINATION FORMAT=SAV NUMBERED=TableNumber_
   OUTFILE='Xtab'.

WEIGHT by Arrests.
crosstabs Agency by OffenseStr by year.

OMSend.

dataset activate Xtab.
select if Var2 EQ "Agency" and Var1 NE "Total".
execute.
delete variables  TableNumber_ to Label_ Var2 Var4.
rename variables (Var1 Var3 = Year Agency).
alter type year(f4.0). /* if you want Year to be numeric.
list.

Bruce Weaver wrote
How about this?

WEIGHT by Arrests.
crosstabs year by Offense.
WEIGHT off.

Stick an appropriate OMS command in front of that to write the table out to a new dataset.  


DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Art Kendall
In reply to this post by Bruce Weaver
If your data were typed in you might want to autorecode offense to look at typos.

Just curious, but might you have multiple counts of arrests.  Could 1 arrest be for homicide and robbery?
Art Kendall
Social Research Consultants
On 12/20/2012 11:10 AM, Bruce Weaver wrote:
How about this?

WEIGHT by Arrests.
crosstabs year by Offense.
WEIGHT off.

Stick an appropriate OMS command in front of that to write the table out to
a new dataset.



DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and
restructure; however, I am not having any luck figuring out the following.
Any advice or assistance concerning possible SYNTAX would be much
appreciated.  I have created for illustrative purposes the abbreviated
current data structure and how I would like to restructure the data.

Current Data:

ID    Year    Agency  Offense Arrests
1     1998    1       Homicide        19
2     1998    1       Robbery 239
3     1999    2       Homicide        22
4     1999    2       Robbery 268

Restructure Data (Wish List):

Year  Agency  Homicide        Robbery
1998  1       19      239
1999  2       22      268

I should note that I have data that dates from 1998 to 2010, and
approximately 52 offense categories (A100), and 41 agencies (A9), and the
Arrests variable is numeric (6).

Thank you in advance.
Damir




-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Transpose-Restructure-Help-Please-tp5717066p5717067.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

David Marso
Administrator
In reply to this post by DKUKEC
Give this a go.

SORT CASES BY  year agency offense .
CASESTOVARS
 /ID =  year agency
 /INDEX = offense
 /GROUPBY = VARIABLE /DROP ID.

DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
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: Transpose & Restructure Help Please

David Marso
Administrator
In reply to this post by Bruce Weaver
I suspect OP wants agency as additional strata?
Impossible to tell from overly specific example data.
--
Bruce Weaver wrote
How about this?

WEIGHT by Arrests.
crosstabs year by Offense.
WEIGHT off.

Stick an appropriate OMS command in front of that to write the table out to a new dataset.  


DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
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: Transpose & Restructure Help Please

Bruce Weaver
Administrator
Yep, I noticed that just after hitting send on my first response.  My second attempt did include Agency.  Here's the result from my second post using my modified input file:

Year Agency Arson Homicide Robbery Total

1998 1         .     19      239    258
1998 4         .     11      118    129
1999 2         0     22      268    290
1999 3        34      0        0     34


And here's the result from your CASESTOVARS:

Year Agency Arson Homicide Robbery

1998    1       .      19     239
1998    4       .      11     118
1999    2       .      22     268
1999    3      34       .       .


Same result, but CASESTOVARS is simpler than CROSSTABS with OMS.  If the OP wants SYSMIS converted to 0, they can use a simple RECODE:

RECODE Arson to Robbery (SYSMIS=0).




David Marso wrote
I suspect OP wants agency as additional strata?
Impossible to tell from overly specific example data.
--
Bruce Weaver wrote
How about this?

WEIGHT by Arrests.
crosstabs year by Offense.
WEIGHT off.

Stick an appropriate OMS command in front of that to write the table out to a new dataset.  


DKUKEC wrote
I have reviewed the FM and various links online concerning transpose and restructure; however, I am not having any luck figuring out the following.  Any advice or assistance concerning possible SYNTAX would be much appreciated.  I have created for illustrative purposes the abbreviated current data structure and how I would like to restructure the data.

Current Data:

ID Year Agency Offense Arrests
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268

Restructure Data (Wish List):

Year Agency Homicide Robbery
1998 1 19 239
1999 2 22 268

I should note that I have data that dates from 1998 to 2010, and approximately 52 offense categories (A100), and 41 agencies (A9), and the Arrests variable is numeric (6).

Thank you in advance.
Damir
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Transpose & Restructure Help Please

TheisenM@adea.org



I am currently out of the office and will be returning Tuesday, December 4. 

Thank you,
McKayla

Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

DKUKEC
In reply to this post by David Marso
Dave's SYNTAX did the trick.

For those offenses that are more than one word, they don't translate directly to the varaible name so Armed Robbery is now V1.  Besisdes RECODE before restructering or RENAME VARIABLE after, is there a better way?  

Thank you again Dave.

Damir
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Bruce Weaver
Administrator
Use the REPLACE function to remove spaces between words (as shown below).  Alternatively, you could replace the blanks with some other character, such as "_".

new file.
dataset close all.

data list list / ID(f2.0) Year(f4.0) Agency(f2.0) Offense(A15) Arrests(f5.0).
begin data
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268
5 1999 3 Arson 34
6 1998 4 Homicide 11
7 1998 4 "Armed Robbery" 118
end data.

compute Offense = REPLACE(Offense," ","").
execute.

SORT CASES BY  year agency offense .
CASESTOVARS
 /ID =  year agency
 /INDEX = offense
 /GROUPBY = VARIABLE /DROP ID.

RECODE Arson to Robbery (SYSMIS=0).
LIST.


DKUKEC wrote
Dave's SYNTAX did the trick.

For those offenses that are more than one word, they don't translate directly to the varaible name so Armed Robbery is now V1.  Besisdes RECODE before restructering or RENAME VARIABLE after, is there a better way?  

Thank you again Dave.

Damir
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Art Kendall
In reply to this post by DKUKEC
Building on posts from Bruce and David see if this is what you want.
new file.
data list list / ID(f2.0) Year(f4.0) Agency(f2.0) OffenseStr(A25)
Arrests(f5.0).
begin data
1 1998 1 Homicide 19
2 1998 1 Robbery 239
3 1999 2 Homicide 22
4 1999 2 Robbery 268
5 1999 3 Arson 34
6 1998 4 Homicide 11
7 1998 4 Robbery 118
9 1998 4 "armed robbery" 72
10 1998 4 'Breaking and entering' 44
11 1998 1 "Armed Robbery" 33
12 1999 1 "armedrobbery" 34
13 1999 4 "breaking and entering" 47
end data.
dataset name raw.

autorecode variables = OffenseStr /into OffenseTemp/print.
recode offensetemp (1,2,3=2) (5,6=6)(else=copy).
autorecode variables=offensetemp /into offensetemp2/print.
string offense(a20).
compute offense=replace(valuelabel(offensetemp2)," ","").
list variables=offense.
delete variables OffenseStr OffenseTemp offensetemp2.

SORT CASES BY  year agency offense .
CASESTOVARS
 /ID =  year agency
 /INDEX = offense
 /GROUPBY = VARIABLE /DROP ID.



Art Kendall
Social Research Consultants
On 12/20/2012 2:21 PM, DKUKEC wrote:
Dave's SYNTAX did the trick.

For those offenses that are more than one word, they don't translate
directly to the varaible name so Armed Robbery is now V1.  Besisdes RECODE
before restructering or RENAME VARIABLE after, is there a better way?

Thank you again Dave.

Damir



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Transpose-Restructure-Help-Please-tp5717066p5717075.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

DKUKEC
In reply to this post by Bruce Weaver
Thank you to Art, Dave and Bruce... great suggestions that i used to apply to the complete aggregate table.  I have included it below just to see how I used it after all of the great imput.  I learned something new... VAR Names do not like " ", "-", & "/".

Here is the SYNTAX that I used to help me with my original challenge.  Thank you again for your amazing assistance.

*********************************************************************

autorecode variables = Offense /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense1(A60).
compute offense1=replace(valuelabel(offensetemp2)," ","").
list variables=offense1.
delete variables Offense OffenseTemp offensetemp2.

autorecode variables = Offense1 /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense2 (A60).
compute offense2=replace(valuelabel(offensetemp2),"/","").
list variables=offense2.
delete variables Offense1 OffenseTemp offensetemp2.

autorecode variables = Offense2 /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense (A60).
compute offense=replace(valuelabel(offensetemp2),"-","").
list variables=offense.
delete variables Offense2 OffenseTemp offensetemp2.

SORT CASES BY  year ori offense .
CASESTOVARS
 /ID =  year ori
 /INDEX = offense
/GROUPBY = VARIABLE /DROP ID.

MATCH FILES FILE= * /KEEP = YEAR ORI ORIS Murder Manslaughter ForcibleSexOffenses ForcibleRape ForcibleSodomy ForcibleFondling Robbery AggravatedAssault AggravatedStalking Burglary LarcenyTheft PocketPicking PurseSnatching
Shoplifting FromBuilding FromCoinOperatedDevice FromMotorVehicle Bicycles MotorVehicleParts AllOther MotorVehicleTheft KidnapAbduction Arson SimpleAssault SimpleStalking DrugsNarcoticsOffenses DrugsNarcotics DrugsEquipment Bribery
Embezzlement Fraud FalsePretensesSwindling CreditCardATM Impersonation Welfare Wire CounterfeitForgery ExtortionBlackmail Intimidation Prostitution NonForcibleSexOffenses SexOffense Obscenity BuyReceivePoss.StolenProperty
DUI DestructionDamageVandalism Gambling WeaponsViolations LiquorLawViolations Miscellaneous TOTAL.

SORT CASES BY ORI YEAR (A).

SAVE OUTFILE='C:\TEMP\UCR CaseToVars.sav'
  /COMPRESSED.

***************************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

David Marso
Administrator
"I learned something new... VAR Names do not like " ", "-", & "/" ".
Pop quiz:  
1. Why do you think that is?  
2. What other characters do you think sh(w)ould also be excluded from valid variable names?
--
DKUKEC wrote
Thank you to Art, Dave and Bruce... great suggestions that i used to apply to the complete aggregate table.  I have included it below just to see how I used it after all of the great imput.  I learned something new... VAR Names do not like " ", "-", & "/".

Here is the SYNTAX that I used to help me with my original challenge.  Thank you again for your amazing assistance.

*********************************************************************

autorecode variables = Offense /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense1(A60).
compute offense1=replace(valuelabel(offensetemp2)," ","").
list variables=offense1.
delete variables Offense OffenseTemp offensetemp2.

autorecode variables = Offense1 /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense2 (A60).
compute offense2=replace(valuelabel(offensetemp2),"/","").
list variables=offense2.
delete variables Offense1 OffenseTemp offensetemp2.

autorecode variables = Offense2 /into OffenseTemp/print.
autorecode variables=offensetemp /into offensetemp2/print.
string offense (A60).
compute offense=replace(valuelabel(offensetemp2),"-","").
list variables=offense.
delete variables Offense2 OffenseTemp offensetemp2.

SORT CASES BY  year ori offense .
CASESTOVARS
 /ID =  year ori
 /INDEX = offense
/GROUPBY = VARIABLE /DROP ID.

MATCH FILES FILE= * /KEEP = YEAR ORI ORIS Murder Manslaughter ForcibleSexOffenses ForcibleRape ForcibleSodomy ForcibleFondling Robbery AggravatedAssault AggravatedStalking Burglary LarcenyTheft PocketPicking PurseSnatching
Shoplifting FromBuilding FromCoinOperatedDevice FromMotorVehicle Bicycles MotorVehicleParts AllOther MotorVehicleTheft KidnapAbduction Arson SimpleAssault SimpleStalking DrugsNarcoticsOffenses DrugsNarcotics DrugsEquipment Bribery
Embezzlement Fraud FalsePretensesSwindling CreditCardATM Impersonation Welfare Wire CounterfeitForgery ExtortionBlackmail Intimidation Prostitution NonForcibleSexOffenses SexOffense Obscenity BuyReceivePoss.StolenProperty
DUI DestructionDamageVandalism Gambling WeaponsViolations LiquorLawViolations Miscellaneous TOTAL.

SORT CASES BY ORI YEAR (A).

SAVE OUTFILE='C:\TEMP\UCR CaseToVars.sav'
  /COMPRESSED.

***************************************************************************
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
|

Automatic reply: Transpose & Restructure Help Please

Morris, Ramona (MCSCS)
I'm sorry I can't reply to you.  I will be out of the office until February 1, 2013.

For Research assistance please contact Janice Mokanski:  [hidden email] or by phone 519 773 4298.

For Promotional examination inquiries please contact Brian McNair: [hidden email] or by phone 519 773 4288.

Thank you
Ramona Morris
R&E Ontario Police College

=====================
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: Transpose & Restructure Help Please

DKUKEC
In reply to this post by David Marso
I gather that it has to do with other syntax rules and functions... it would create a mess when a variable has characters used for computing for example... such as division or subtraction!  However, I suspect that I have failed the pop quiz.  Thank you again Dave for your help.  It is very much appreciated.

Cheers,
Damir
Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

David Marso
Administrator
"it would create a mess when a variable has characters used for computing for example... such as division or subtraction!"
You are certainly on the right track!
Add *, ^, &, | (multiply, exponent, AND, OR) and several others ! ' " ,
BTW I prefer David to Dave (can't leave the ID out of the David).

DKUKEC wrote
I gather that it has to do with other syntax rules and functions... it would create a mess when a variable has characters used for computing for example... such as division or subtraction!  However, I suspect that I have failed the pop quiz.  Thank you again Dave for your help.  It is very much appreciated.

Cheers,
Damir
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: Transpose & Restructure Help Please

Albert-Jan Roskam
In reply to this post by DKUKEC
This seems to be a way to validate variable names. Keep in mind that varnames that start with a pound char have a special meaning (they are throw-away scratch variables). Same applies to $ prefix ($time, $date, etc), but you cannot define these yourself. This does not check whether this is a 'smart' name. I don't think it's illegal to use varnames such as anova, from, to, etc, but it's a bad idea for sure.

>>> import re
>>> isValid = lambda varName: bool(re.match("^#?[a-z]+\w+$", varName, re.I | re.U))
>>> isValid("#scratch")
True
>>> isValid("$sysmis")
False
>>> isValid("12n_n")
False
>>> isValid("ike&tina")
False
>>> isValid("x * y")
False
>>> isValid("var_1")
True
>>> isValid("_var_1")
False




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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


----- Original Message -----

> From: DKUKEC <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Friday, December 21, 2012 4:59 PM
> Subject: Re: [SPSSX-L] Transpose & Restructure Help Please
>
>T hank you to Art, Dave and Bruce... great suggestions that i used to apply to
> the complete aggregate table.  I have included it below just to see how I
> used it after all of the great imput.  I learned something new... VAR Names
> do not like " ", "-", & "/".
>
> Here is the SYNTAX that I used to help me with my original challenge.  Thank
> you again for your amazing assistance.
>
> *********************************************************************
>
> autorecode variables = Offense /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense1(A60).
> compute offense1=replace(valuelabel(offensetemp2)," ","").
> list variables=offense1.
> delete variables Offense OffenseTemp offensetemp2.
>
> autorecode variables = Offense1 /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense2 (A60).
> compute offense2=replace(valuelabel(offensetemp2),"/","").
> list variables=offense2.
> delete variables Offense1 OffenseTemp offensetemp2.
>
> autorecode variables = Offense2 /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense (A60).
> compute offense=replace(valuelabel(offensetemp2),"-","").
> list variables=offense.
> delete variables Offense2 OffenseTemp offensetemp2.
>
> SORT CASES BY  year ori offense .
> CASESTOVARS
> /ID =  year ori
> /INDEX = offense
> /GROUPBY = VARIABLE /DROP ID.
>
> MATCH FILES FILE= * /KEEP = YEAR ORI ORIS Murder Manslaughter
> ForcibleSexOffenses ForcibleRape ForcibleSodomy ForcibleFondling Robbery
> AggravatedAssault AggravatedStalking Burglary LarcenyTheft PocketPicking
> PurseSnatching
> Shoplifting FromBuilding FromCoinOperatedDevice FromMotorVehicle Bicycles
> MotorVehicleParts AllOther MotorVehicleTheft KidnapAbduction Arson
> SimpleAssault SimpleStalking DrugsNarcoticsOffenses DrugsNarcotics
> DrugsEquipment Bribery
> Embezzlement Fraud FalsePretensesSwindling CreditCardATM Impersonation
> Welfare Wire CounterfeitForgery ExtortionBlackmail Intimidation Prostitution
> NonForcibleSexOffenses SexOffense Obscenity BuyReceivePoss.StolenProperty
> DUI DestructionDamageVandalism Gambling WeaponsViolations
> LiquorLawViolations Miscellaneous TOTAL.
>
> SORT CASES BY ORI YEAR (A).
>
> SAVE OUTFILE='C:\TEMP\UCR CaseToVars.sav'
>   /COMPRESSED.
>
> ***************************************************************************
>
>
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/Transpose-Restructure-Help-Please-tp5717066p5717091.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
>

=====================
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
|

Automatic reply: Transpose & Restructure Help Please

TheisenM@adea.org


I am currently out of the office and have limited access to email. I will get back to you as soon as possible. 


Thank you,
McKayla

Reply | Threaded
Open this post in threaded view
|

Re: Transpose & Restructure Help Please

Jon K Peck
In reply to this post by Albert-Jan Roskam
Actually variable names can be a bit more general than this re suggests.  For example, accented or nonwestern characters are valid in the first position.  Even circled Hangul characters are valid in a name.  But there are a few reserved names:
ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO, and WITH.
Names are limited to 64 bytes in length.

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Albert-Jan Roskam <[hidden email]>
To:        [hidden email],
Date:        12/22/2012 10:44 AM
Subject:        Re: [SPSSX-L] Transpose & Restructure Help Please
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




This seems to be a way to validate variable names. Keep in mind that varnames that start with a pound char have a special meaning (they are throw-away scratch variables). Same applies to $ prefix ($time, $date, etc), but you cannot define these yourself. This does not check whether this is a 'smart' name. I don't think it's illegal to use varnames such as anova, from, to, etc, but it's a bad idea for sure.

>>> import re
>>> isValid = lambda varName: bool(re.match("^#?[a-z]+\w+$", varName, re.I | re.U))
>>> isValid("#scratch")
True
>>> isValid("$sysmis")
False
>>> isValid("12n_n")
False
>>> isValid("ike&tina")
False
>>> isValid("x * y")
False
>>> isValid("var_1")
True
>>> isValid("_var_1")
False




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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


----- Original Message -----
> From: DKUKEC <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Friday, December 21, 2012 4:59 PM
> Subject: Re: [SPSSX-L] Transpose & Restructure Help Please
>
>T hank you to Art, Dave and Bruce... great suggestions that i used to apply to
> the complete aggregate table.  I have included it below just to see how I
> used it after all of the great imput.  I learned something new... VAR Names
> do not like " ", "-", & "/".
>
> Here is the SYNTAX that I used to help me with my original challenge.  Thank
> you again for your amazing assistance.
>
> *********************************************************************
>
> autorecode variables = Offense /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense1(A60).
> compute offense1=replace(valuelabel(offensetemp2)," ","").
> list variables=offense1.
> delete variables Offense OffenseTemp offensetemp2.
>
> autorecode variables = Offense1 /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense2 (A60).
> compute offense2=replace(valuelabel(offensetemp2),"/","").
> list variables=offense2.
> delete variables Offense1 OffenseTemp offensetemp2.
>
> autorecode variables = Offense2 /into OffenseTemp/print.
> autorecode variables=offensetemp /into offensetemp2/print.
> string offense (A60).
> compute offense=replace(valuelabel(offensetemp2),"-","").
> list variables=offense.
> delete variables Offense2 OffenseTemp offensetemp2.
>
> SORT CASES BY  year ori offense .
> CASESTOVARS
> /ID =  year ori
> /INDEX = offense
> /GROUPBY = VARIABLE /DROP ID.
>
> MATCH FILES FILE= * /KEEP = YEAR ORI ORIS Murder Manslaughter
> ForcibleSexOffenses ForcibleRape ForcibleSodomy ForcibleFondling Robbery
> AggravatedAssault AggravatedStalking Burglary LarcenyTheft PocketPicking
> PurseSnatching
> Shoplifting FromBuilding FromCoinOperatedDevice FromMotorVehicle Bicycles
> MotorVehicleParts AllOther MotorVehicleTheft KidnapAbduction Arson
> SimpleAssault SimpleStalking DrugsNarcoticsOffenses DrugsNarcotics
> DrugsEquipment Bribery
> Embezzlement Fraud FalsePretensesSwindling CreditCardATM Impersonation
> Welfare Wire CounterfeitForgery ExtortionBlackmail Intimidation Prostitution
> NonForcibleSexOffenses SexOffense Obscenity BuyReceivePoss.StolenProperty
> DUI DestructionDamageVandalism Gambling WeaponsViolations
> LiquorLawViolations Miscellaneous TOTAL.
>
> SORT CASES BY ORI YEAR (A).
>
> SAVE OUTFILE='C:\TEMP\UCR CaseToVars.sav'
>   /COMPRESSED.
>
> ***************************************************************************
>
>
>
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/Transpose-Restructure-Help-Please-tp5717066p5717091.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
>

=====================
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


12