BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Novice22
Quartz | Level 8

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:

SAS_Novice22_0-1654543729669.png

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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:

SAS_Novice22_0-1654545120953.png

I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post. 

SAS_Novice22_1-1654545165498.png

Here is the log I get:

SAS_Novice22_2-1654545346570.png

Thank you.

T.


 

View solution in original post

10 REPLIES 10
Tom
Super User Tom
Super User

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.

 

 

PaigeMiller
Diamond | Level 26

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
SAS_Novice22
Quartz | Level 8
Replied to my original post, please let me know if that provides the needed clarification.
SAS_Novice22
Quartz | Level 8

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:

SAS_Novice22_0-1654545120953.png

I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post. 

SAS_Novice22_1-1654545165498.png

Here is the log I get:

SAS_Novice22_2-1654545346570.png

Thank you.

T.

Reeza
Super User

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:

SAS_Novice22_0-1654545120953.png

I would like the following labels to be applied instead of the numeric numbers. The text format has been included in the original post. 

SAS_Novice22_1-1654545165498.png

Here is the log I get:

SAS_Novice22_2-1654545346570.png

Thank you.

T.


 

SAS_Novice22
Quartz | Level 8
Thank you again for the help!
Tom
Super User Tom
Super User

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.

SAS_Novice22
Quartz | Level 8
Thank you Tom, that makes sense I will figure out how to use the insert SAS code to get the pop-up window to paste the code for the forum for next time,
Thank you again for the solution.
T.
sbxkoenk
SAS Super FREQ

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_Novice22
Quartz | Level 8
Very helpful, Koen. Thank you, that is the solution to my problem. Thank you for the great explanation and the information.
T.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 10 replies
  • 943 views
  • 3 likes
  • 5 in conversation