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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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