11-02-2014 04:01 AM
I was sent an SPSS dataset which I converted to SAS dataset. Most of the SPSS variables had value labels; for example, for the Sex variable, it was coded as 1='Male" and 2='Female'. I was able to use the proc format to define all the value labels in SAS. My goal (i.e., my question) is to make the value labels become the value in the dataset. For example, instead of 1 and 2 (and the associated format) for Sex, I want the Sex (or a new variable based on Sex) to be Male and Female. The motivation of doing this is because some of the variables have a few thousand value labels and it's so much easier to just read what the true label of each value. Plus, I've to merge other variables from another dataset and that dataset only has the labels (not value). In other words, in the dataset that was imported from SPSS, Sex is 1='Male' and 2='Male'. The other dataset has Sex has 'Male' and 'Female'. Even though I used Sex as an example, I'll be merging the two dataset using variables that have thousands of value labels.
Thanks for your assistance.
11-02-2014 05:23 AM
That would be easy if you already have SEX format.
proc format; value fmt 1='Male' 2='Female'; run; data x; a=1;output; a=2;output; format a fmt.; run; data want; set x; b=vvalue(a); run;
11-02-2014 06:04 AM
The value statement in SPSS is the format statement of SAS. Both are recoding the internal value
Within SPSS the values are stored in the SPSS dataset and with SAS they are own components. Using the SAS formats in work is easily done. In a permanent way you can activate that by setting the fmtsearch option. SAS(R) 9.3 System Options: Reference, Second Edition. This is not needed with SPSS but you need that with SAS.
Having the formats available you can associate those with the variables SAS(R) 9.3 Statements: Reference By this the representation and the internal value are kept segregated.
The SAS formats are richer than the SPSS values. As you can have the variables getting well readable in both. With SAS is more easy to change formats for recoding or having mulii-value ones.
I would advice to keep the original values untouched and take your benefits from all functionality with formats.
Defining formats is: Base SAS(R) 9.3 Procedures Guide, Second Edition (proc format)
11-02-2014 10:07 PM
value abc 1="Female"
create table have as
select name, age, case sex
when "F" then 1
end as ind
select * from have;
11-03-2014 01:36 AM
Hi Xia, Jaap and bharathtuppad,
Thank you all for your helpful suggestions and syntax codes. I really appreciate it. While the code will work if you have a simple variable like Sex with only 2 values, the variables that I was hoping to convert have about 5,000 value labels. So, the coding time may be too much for the benefit. I was hoping there would be a simple and quick solution but it doesn't seem to be the case. Thank you again for your kind assistance.
11-03-2014 01:52 PM
With your last reply your are saying that the question was:
- how to convert SPSS values statements to SAS proc format value statements.
When it is coded clean and you can read and process the SPSS source code it could be done with a SAS program
11-04-2014 07:35 AM
5000 values are no problem for a SAS value format; as long as you have data that you can convert to cntlin format for the format procedure, you're fine.
11-03-2014 02:16 PM
You give up too easily! Since you already have and have applied the formats, why not just export and then import the file? E.g.:
/*Create some format and formatted data for testing*/
format sex $sex.;
format age age.;
format height height.;
format weight weight.;
/*Export the formatted file*/
filename tempfile temp;
proc export data=have outfile=tempfile
/*Import the formatted file*/
proc import datafile=tempfile out=want