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 | Cumulative |
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!!!!
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.
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.
This makes so much more sense! I really appreciate your help. Thank you so much!
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.
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: