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.
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.
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?
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.
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.