BookmarkSubscribeRSS Feed
Amanda_Lemon
Quartz | Level 8

Hello,

 

I have a categorical variable (e.g., Race) in a sav dataset. Race has multiple levels and is coded as 1, 2, 3, etc. Each level has a label, e.g., White, Asian, etc. When I run proc freq in SAS, the table displays only the labels but not numerical codes. Is there a way to display both numerical codes and labels?

 

I want to recode the variable, and for that I need to see which number corresponds to which label (i.e., that 1 is White, that 2 is Hispanic, etc.). And I am not sure how to do that unless I open the file in SPSS.

 

Thank you in advance.

4 REPLIES 4
Astounding
PROC Star

Given that you already have the labeled version, try adding this to your PROC FREQ:

 

format race;

 

That should give you the unlabeled version, so you can match them up.

 

Note that there doesn't have to be a one-to-one match.  It is conceivable that the labeling combines two numeric values into a single category.

Amanda_Lemon
Quartz | Level 8

That helps! Thank you!

 

I can match them up since my data is not very complex. But one can potentially have more complex coding with multiple numeric codes labeled in the same way or the number of cases per group can be the same, which will complicate the matching process. So, there is no way to see the coding schema in SAS directly?

Astounding
PROC Star

Yes, but you need to know a bit about where the pieces get saved.

 

SAS saves the translations as a format.  If you know the location of the formats, you can set up a LIBNAME statement to identify the location.  Assuming you define "mylib" within the LIBNAME statement, you could then use:

 

proc format library=mylib fmtlib;

run;

 

That should print all the translations you would ever want to see.

Reeza
Super User

If you export your data from SPSS you have an option to create a format file. Those formats can then be applied to the SAS dataset. 

 

Older version but think it still applies 

http://support.sas.com/documentation/cdl/en/acpcref/63184/HTML/default/viewer.htm#a003103775.htm

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 796 views
  • 1 like
  • 3 in conversation