BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmh
Calcite | Level 5 kmh
Calcite | Level 5

Hello! I'm trying to label my variable "lmath" with "1=stag" "2=ag" and so forth  using proc format (coding below)  However, whenever I run the frequency table to check that proc format worked I get the table below.  The reason my labels are so short is I read somewhere the labels need to be less than 8 characters long, but shortening the labels did not work. I'm using SAS university edition. 

 

lmath

Frequency

Percent

Cumulative
Frequency

Cumulative
Percent

Frequency Missing = 4599

1

2254

19.43

2254

19.43

2

6958

59.99

9212

79.43

3

2086

17.99

11298

97.41

4

300

2.59

11598

100.00

 

 

proc format;

value lmath 1='stag' 2='ag' 3='dis' 4'stdis';
run;

 

proc freq;
tables lmath;
run;

 

Any help would be greatly appreciated!!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

It looks like you are trying to FORMAT your variable, not label it. A LABEL is just a single longer description of the variable than the name.

 

You defined the format you wanted to use, but you did not tell SAS to use it for any of your variables.

 

Add a FORMAT statement to your PROC step.

proc freq;
  tables lmath;
  format lmath lmath. ;
run;

 

Note that the name of the format used with a variable is independent of the name of the variable.  You could 20 variables in your dataset that are each coded with 0 as No and 1 and Yes.  So you just need to define one NoYes. format and use it for all of them.

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

It looks like you are trying to FORMAT your variable, not label it. A LABEL is just a single longer description of the variable than the name.

 

You defined the format you wanted to use, but you did not tell SAS to use it for any of your variables.

 

Add a FORMAT statement to your PROC step.

proc freq;
  tables lmath;
  format lmath lmath. ;
run;

 

Note that the name of the format used with a variable is independent of the name of the variable.  You could 20 variables in your dataset that are each coded with 0 as No and 1 and Yes.  So you just need to define one NoYes. format and use it for all of them.

kmh
Calcite | Level 5 kmh
Calcite | Level 5

This makes so much more sense! I really appreciate your help. Thank you so much!

singhsahab
Lapis Lazuli | Level 10

Hello Kmh,

 

I observed that, your code will not work because in PROC FORMAT for the last identifier 4 equal sign (=)  was missing . When you want to use format , you have to tell SAS . 

 

proc format;

value lmath 1='stag' 2='ag' 3='dis' 4='stdis';
run;

 

proc freq;
tables lmath;

Format lmath lmath .
run;

 

kindly try above code. 

kmh
Calcite | Level 5 kmh
Calcite | Level 5
Thank you! Code worked perfectly!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 7781 views
  • 2 likes
  • 3 in conversation