Dear All,
My original SPSS data can be viewed in both numeric and character values, i.e.
1 = Yes; 0 = No; In SPSS, you can either view them in numeric or character format.
When I imported the SPSS data to SAS, the data retains SPSS's character value appearance, but with numeric type.
So I was wondering whether I can convert them to actual character type, and work on those character value.
For example:
Yes
Yes
No
No
appears in SAS data, but their true type is numeric, which are 1 1 0 0.
How can I keep them as character value as (Yes No) when they are imported to SAS ?
Thanks and Regards
Fred
As noticed in SAS, when imported SPSS file, it also create a "formats" sub-directory, which contains all the format of the variables, telling 1 = Yes, 0 = No.
Then the question now will be that how to let character formats as the actual character values rather than numeric ?
Thanks
Fred
Fred,
I may not understand what you are trying to accomplish, but it sounds like you simply want a copy of the file as it would be created by proc sql. Does the following mimic what you are trying to do?:
/* Create format and build test file with formats */
proc format;
value
$gender
'M'='Male'
'F'='Female';
value
agegroup
low-14='Young'
otherwise='Old';
run;
data test;
set sashelp.class;
format sex $gender.;
format age agegroup.;
run;
/* Create a copy of file with formatted values */
proc sql noprint;
create table want as
select name,
put(sex,$gender.) format=$6. AS sex,
put(age,agegroup.) format=$5. AS age,
height,
weight
from work.test
;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.