- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you again for the solution.
T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
T.