Help using Base SAS procedures

Imported categorical variable with values from spss now displays as numeric but when converted to character I lose values

Reply
New Contributor
Posts: 3

Imported categorical variable with values from spss now displays as numeric but when converted to character I lose values

variable in spss is familygrossincome:

0='Unknown or not applicable'

1= 'Less than 20,000'

3= '20,000 to 39,999'

8='40,000 to 59,999'

12='60,000 to 79,999';

When imported, proc contents shows it is numeric. When I run proc freq it displays the levels as text i.e.

Unknown or not applicable

less than 20,000

etc

When I do where statement I have to use numeric value (0, 1, 3, 8 12). I can only tell these are the values by looking at spss I cannot find them in sas

If i make a character copy using familygrossCat= STRIP (PUT(familygrossincome, familygross.) then proc freq only displays 0,1 3, 8, 12)

I guess I have three questions.

1) How do create a categorical variable with the text values not the numbers?

2) If I do copy numbers, how do I get procedures to display the text values (e.g. less than 20,000) instead of numerical value?

3) What is the command to see what the numerical and character values are for a variable? I usually just look at the original spss file

Thank you!

Super User
Posts: 11,343

Re: Imported categorical variable with values from spss now displays as numeric but when converted to character I lose values

It has not been changed to character and attempts to modify it are likely going to misbehave. When you ran proc contents it should have shown you that the variable has a format associated with it, and likely to be the name of the variable. Which is why reference in Where or IF statements you need the 0, 1 etc.

If you want proc freq to show  the 1, 2, 3 values then add a line to the code like:

format familygrossCat best.;

Proc freq by default will use the currently assigned format for any of the variable values.

New Contributor
Posts: 3

Re: Imported categorical variable with values from spss now displays as numeric but when converted to character I lose values

So I am not sure if this how best to approach it but this is what I was able to do:

proc format;

value familygross

0='Unknown or not applicable'

1= 'Less than 20,000'

3= '20,000 to 39,999'

8='40,000 to 59,999'

12='60,000 to 79,999';

run;

proc freq data=FA2013_7;

tables familygrossincome;

format familygrossincome familygross.;

run;

I still do not know how to display values that have been imported for the variable from spss.

Thank you for your response and help!

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