- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Xia Keshan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc format;
value abc 1="Female"
2="Male";
run;
proc sql;
create table have as
select name, age, case sex
when "F" then 1
else 2
end as ind
from sashelp.class;
select * from have;
quit;
data want;
set have;
sex=put(ind, abc.);
run;
proc print;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc format or Hash Table both can do that fast.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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*/
proc format;
value $sex
'M'='Males'
'F'='Females'
;
value age
0-15='Younger'
other='Older'
;
value height
0-65.5='Shorter'
other='Taller'
;
value weight
0-99.9='Lighter'
other='Heavier'
;
run;
data have;
set sashelp.class;
format sex $sex.;
format age age.;
format height height.;
format weight weight.;
run;
/*Export the formatted file*/
filename tempfile temp;
proc export data=have outfile=tempfile
dbms=csv replace;
run;
/*Import the formatted file*/
proc import datafile=tempfile out=want
dbms=csv replace;
run;