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
Opal | Level 21

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
Opal | Level 21

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 702 views
  • 1 like
  • 3 in conversation