BookmarkSubscribeRSS Feed
katemcguckin
Fluorite | Level 6

Hi. It's Kate. 

 

I have a bunch of variables that are coded 0 for NO and 1 for YES.  I know how to change them using procformat to have labels, but when I have about 30 of those variables, is there a fast way to do them all in 1 macro or something? I want to keep the values, I just want to assign the labels. 

 

Thanks.  

 

For example:

 

death     drug A   tx1  trx2   drugb

0           1           1      1     1

1          0             0      1     1

 

I would like assign perm. labels for a whole bunch of those variables and tired of doing it for each one separately. 

thanks. 

 

 

 

 

4 REPLIES 4
Tom
Super User Tom
Super User

@katemcguckin wrote:

Hi. It's Kate. 

 

I have a bunch of variables that are coded 0 for NO and 1 for YES.  I know how to change them using procformat to have labels, but when I have about 30 of those variables, is there a fast way to do them all in 1 macro or something? I want to keep the values, I just want to assign the labels. 

 

Thanks.  

 

For example:

 

death     drug A   tx1  trx2   drugb

0           1           1      1     1

1          0             0      1     1

 

I would like assign perm. labels for a whole bunch of those variables and tired of doing it for each one separately. 

thanks. 

 


I don't understand what you are complaining about.  You just need to define one format and attach it to all of the variables that need it.

proc format ;
  value yesno 1='Yes' 0='No';
run;
data want ;
 set have ;
 format death drug: tx: yesno.;
run;
katemcguckin
Fluorite | Level 6

Hi,

 

I'm NOT complaining! I just wanted some help!

 

Thank you.  I figured it out. 

 

Your code worked, thank you.... Kate. 

 

hashman
Ammonite | Level 13

It's unclear from your post what you mean by "labels". The term "label" in SAS has a specific meaning: It's an attribute of a variable stored in the descriptor of a data file and serves to be surfaced instead of the variable's name if so requested. There're ways to assign and change labels; but since the FORMAT procedure isn't one of them, I guess you mean something else.

 

Perhaps by "labels" you mean formatted values like "Yes" and "No" that you want to see instead of 1 and 0. If so, simply assign the format where 1="Yes" and 0="No" to all your Boolean variables and make sure in your SAS session, SAS knows the path to the library where the compiled format is stored. If you store a data set with these variables and the format assigned to them, then any other data set you create from reading it will inherit the format attached to the variables. Ergo, you need to do the assignment only once. 

Kurt_Bremser
Super User

Your variables need to be "automatable" to make writing a format statement (as already noted, you are NOT talking about labels here!) easier.

Either all numeric variables in your dataset are boolean (in which case you can use the designator _numeric_), or they follow a naming pattern that allows use of wildcards (see @Tom's post). If neither is true, you need to write the format statement variable by variable on your own.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 899 views
  • 1 like
  • 4 in conversation