Help using Base SAS procedures

Proc Freq

Reply
Contributor
Posts: 58

Proc Freq

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.

Super User
Posts: 6,789

Re: Proc Freq

Posted in reply to Amanda_Lemon

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.

Contributor
Posts: 58

Re: Proc Freq

[ Edited ]
Posted in reply to Astounding

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?

Super User
Posts: 6,789

Re: Proc Freq

Posted in reply to Amanda_Lemon

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.

Super User
Posts: 23,791

Re: Proc Freq

Posted in reply to Amanda_Lemon

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

Ask a Question
Discussion stats
  • 4 replies
  • 122 views
  • 1 like
  • 3 in conversation