DATA Step, Macro, Functions and more

How to work on imported SPSS (*.sav) file in SAS ?

Reply
Contributor
Posts: 56

How to work on imported SPSS (*.sav) file in SAS ?

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

Contributor
Posts: 56

How to work on imported SPSS (*.sav) file in SAS ?

Posted in reply to Fred_Gavin

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

PROC Star
Posts: 7,492

Re: How to work on imported SPSS (*.sav) file in SAS ?

Posted in reply to Fred_Gavin

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;

Ask a Question
Discussion stats
  • 2 replies
  • 154 views
  • 0 likes
  • 2 in conversation