Example syntax for sorting string or numeric variables by contents.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Example syntax for sorting string or numeric variables by contents.

Art Kendall
In response to an earlier post on this list Jon Peck suggested using spssinc trans to sort variables
so I wrote this example syntax for my examples folder.

* sorting variables within cases by contents.
* the sort variables procedure does not sort on contents.
* this example syntax sorts string variables then numeric variables.
data list list (",") /id (f1) Category1 Category2 Category3(3a20).
begin data
   1,clothing,mens clothes,shirts
   2,accessories,womens,handbags
   3,mens clothes,shirts,clothing
end data.
*The input list of variables cannot use TO, the result list can use TO.
*The type is a single default value for all variables or a series of values.
* 0 for numeric, string length for strings.
*.
* sort string variables.
spssinc trans result = Cat1 TO Cat3 type=20
   /formula "sorted([Category1, Category2, Category3])".
*note that the new string are right justified.
execute.
*.
* sort numeric variables.
autorecode
   variables =  Category1  Category2  Category3
   /into       nCategory1 nCategory2 nCategory3
   /group /print.
spssinc trans result = nCat1 TO nCat3 type=0
   /formula "sorted([nCategory1, nCategory2, nCategory3])".
formats nCat1 to nCat3 (f2).
*spssinc trans /help.


-- 
Art Kendall
Social Research Consultants
Art Kendall
Social Research Consultants