BookmarkSubscribeRSS Feed
Fred_Gavin
Calcite | Level 5

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

2 REPLIES 2
Fred_Gavin
Calcite | Level 5

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

art297
Opal | Level 21

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 976 views
  • 0 likes
  • 2 in conversation