Hi everyone,
I am very new to SAS and would appreciate any assistance. I would like to take the new variable I generated and give labels to the numeric codes to create easy interpretation.
Here is what the data looks like:
Here is my code (which is not working):
PROC FORMAT;
VALUE RACE 1="ASIAN"
2="BLACK"
3="PACIFIC"
4="WHITE"
5="OTHER";
RUN;
Thank you in advance for any help you can provide.
T.
You need to provide your code as text, not as images.
You created a format you never used it. You use a format using a FORMAT statement.
For more information on formats read this paper https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf
proc format; value age_cat low - 12 = 'Pre-Teen' 13 - 16 = 'Teen' 16 - high = 'Young Adult'; run; proc freq data=sashelp.class; table age; format age age_cat.; run;
@SAS_Novice22 wrote:
Thank you to provide more clarity. I would like the proc print tables to show the new labels, with the code I use above here is what the data still looks like:
I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post.
Here is the log I get:
Thank you.
T.
Your posted code looks fine for creating a format named RACE to decode those 5 values into text.
What code did you use to tell SAS to use that format with your existing variable?
Please show the code that did not work.
When you say "it is not working" and provide no other details, we are left in the dark. Please explain WHAT is not working, and how you know it is not working. Provide information. And show us your code.
Thank you to provide more clarity. I would like the proc print tables to show the new labels, with the code I use above here is what the data still looks like:
I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post.
Here is the log I get:
Thank you.
T.
You need to provide your code as text, not as images.
You created a format you never used it. You use a format using a FORMAT statement.
For more information on formats read this paper https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf
proc format; value age_cat low - 12 = 'Pre-Teen' 13 - 16 = 'Teen' 16 - high = 'Young Adult'; run; proc freq data=sashelp.class; table age; format age age_cat.; run;
@SAS_Novice22 wrote:
Thank you to provide more clarity. I would like the proc print tables to show the new labels, with the code I use above here is what the data still looks like:
I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post.
Here is the log I get:
Thank you.
T.
Somewhere you need a FORMAT statement to tell SAS that you want to use the format to display the variable.
Either in the step that creates the dataset or the step that produces the report.
format race race. ;
Please post text as text and not photographs. Especially code. Use the Insert SAS Code button to get a pop-up window to paste the code so the forum doesn't treat the code as paragraphs.
Hello,
You have created the format.
But did you make a "link" between the VARIABLE named RACE and the FORMAT named RACE?
Here's how you can do it :
data work.have;
race=1; output;
race=2; output;
race=3; output;
race=4; output;
race=5; output;
run;
PROC FORMAT;
VALUE RACE 1="ASIAN"
2="BLACK"
3="PACIFIC"
4="WHITE"
5="OTHER";
RUN;
PROC DATASETS LIBRARY=WORK NoList memtype=DATA;
modify have;
format race race.;
run;
PROC PRINT NOOBS; RUN;
/* end of program */
As the format is by default stored in WORK.FORMATS you must recreate it in every SAS session again.
Koen
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.