My observations has a field called "city". It is coded with ~40 numbers.
.e.g NewYork is 0, Berlin is 1, ... Of course I want to set the lables for each value but I don't want to do this manually. I have a another table (as a csv-file) holding the values for the code numbers. CODE;CITY 0;NewYork 1;Berlin ... Is there a way in SPSS to use that csv-file to set the labels (not the values!) automaticly? An acceptable workaround would be when there is a way to change the values from numbers to the city names. ===================== 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 |
Another workaround would be to copy your list into Word (or Notepad) and make changes manually. 0;NewYork 1;Berlin ~ ~ ~ . . but it’s quicker to use Ctrl+H to change ; to [space] " 0 "NewYork 1 "Berlin ~ ~ ~ . . and the line ends ^p^p to " 0 "NewYork" 1 "Berlin" ~ ~ ~ Then copy the list into a syntax file value labels city 0 "NewYork" 1 "Berlin" ~ ~ ~ . [Don’t forget the full stop!] John F Hall (Mr) [Retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com SPSS start page: www.surveyresearch.weebly.com/1-survey-analysis-workshop -----Original Message----- My observations has a field called "city". It is coded with ~40 numbers. .e.g NewYork is 0, Berlin is 1, ... Of course I want to set the lables for each value but I don't want to do this manually. I have a another table (as a csv-file) holding the values for the code numbers. CODE;CITY 0;NewYork 1;Berlin ... Is there a way in SPSS to use that csv-file to set the labels (not the values!) automaticly? An acceptable workaround would be when there is a way to change the values from numbers to the city names. ===================== 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 |
On 2016-09-19 10:13 John F Hall <[hidden email]> wrote:
> Another workaround would be to copy your list into Word (or Notepad) > and make changes manually. Yes, using a good texteditor (instead of a word processor) is my current "solution". If there would be more value labels and fields I would do that with a python script. Let's specify my question: I am looking for a SPSS solution. Is it possible with SPSS? ===================== 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 |
In reply to this post by Christian Buhtz
Using the extension command, STATS VALLBLS FROMDATA, you can do this. It would require you to match the labels dataset with a BY so as to align the label values with the main dataset values. Excerpt from the help below. Another way to do this would be to use the extendedTransforms.vlookup function with the SPSSINC TRANS extension command. In that usage, you create a dataset containing the city index and the label (same as in the first approach) and apply that with TRANS. I can spell that out further if you want to go that route. From the STAT VALLBLS FROMDATA extension... Example: STATS VALLBLS FROMDATA VARIABLES = x1 TO x5
LBLVARS = label. This command creates value labels for a set of variables using values of other variables for the labels. If x is a variable having values 1,2,3 and xlabel is a variable having values 'a', 'b', 'c', value labels for x are created as
On Mon, Sep 19, 2016 at 1:23 AM, Christian Buhtz <[hidden email]> wrote: My observations has a field called "city". It is coded with ~40 numbers. |
In reply to this post by Christian Buhtz
John's solution is to use a text editor in order to write a VALUE LABELS command,
=====================
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
which you then insert into your file. In an old-style "hack", you could use SPSS as the text editor to read and re-write the csv-file so that everything would be in SPSS. Jon's solution was terse in saying that you MATCH FILES between the data and the csv-file as the first step, using TABLE= for the csv-file to add the name as an additional variable. Before (or without) employing his further solution, that already gives you a variable that has the city names, and thus provides what you describe as "an acceptable workaround" -- names to use instead of the values. -- Rich Ulrich > Date: Mon, 19 Sep 2016 09:23:35 +0200 > From: [hidden email] > Subject: Set labels based on table > To: [hidden email] > > My observations has a field called "city". It is coded with ~40 numbers. > .e.g NewYork is 0, Berlin is 1, ... > > Of course I want to set the lables for each value but I don't want to > do this manually. I have a another table (as a csv-file) holding the > values for the code numbers. > > CODE;CITY > 0;NewYork > 1;Berlin > ... > > Is there a way in SPSS to use that csv-file to set the labels (not the > values!) automaticly? > > An acceptable workaround would be when there is a way to change the > values from numbers to the city names. > |
It's true that just substituting the matched string variable for the numeric code would be a solution, but the value labels approach has some advantages.
The value label representation is smaller, although this is unlikely to matter unless the dataset is very large. A few procedures, particularly CTABLES and GGRAPH and VALIDATE DATA can use the value labels for more than just labeling. Also, the gui takes advantage of this. Once the labels dataset is created, it's a single command to make the labels, so the work is about the same either way, but there may not be a compelling reason to choose between them. On Monday, September 19, 2016, Rich Ulrich <[hidden email]> wrote:
-- ===================== 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 |
Free forum by Nabble | Edit this page |