BookmarkSubscribeRSS Feed
Herrera524
SAS Employee

Good morning everyone

I wanted to ask you how I can make the name that I am assigning to the etequieta be modified in the output of the table

data test;
set test;
label due_in_1_Fixed=due in one your or less fixed rate
;
run;
proc datasets librery=work;
modify test;
label due_in_1_Fixed=due in one your or less fixed rate;
quit;

proc print data=test label;
label due_in_1_Fixed=due in one your or less fixed rate;
var due_in_1_Fixed;
run;

print.png

 

10 REPLIES 10
Reeza
Super User
 
*Create sample dataset to apply label;
data class;
set sashelp.class;
label Sex="Gender" height="Height (in)"weight="Weight (lbs)";
run;
 
 title 'Show labels';
 proc print data=class(obs=5) label noobs;
 run;
 
  title 'Override labels';
 proc print data=class(obs=5) label noobs;
 label height ="Height (cm)" weight="Weight (kgs)";
 run;
 
 

Reeza_0-1694540497839.png


@Herrera524 wrote:

Good morning everyone

I wanted to ask you how I can make the name that I am assigning to the etequieta be modified in the output of the table

data test;
set test;
label due_in_1_Fixed=due in one your or less fixed rate
;
run;
proc datasets librery=work;
modify test;
label due_in_1_Fixed=due in one your or less fixed rate;
quit;

proc print data=test label;
label due_in_1_Fixed=due in one your or less fixed rate;
var due_in_1_Fixed;
run;

print.png

 


 

Herrera524
SAS Employee

I tried to do it according to the example that you shared with me but it does not assign the label to the column name

PaigeMiller
Diamond | Level 26

@Herrera524 wrote:

I tried to do it according to the example that you shared with me but it does not assign the label to the column name


The code from @Reeza works for me.

 

It is never sufficient to say code does not work, and provide no other information. Specifically, from now on when code doesn't work, show us the code AND show us what is wrong — either show us the incorrect results, or if there are errors in the log then please show us the entire log for this piece of code

--
Paige Miller
Herrera524
SAS Employee

Hi
The code works perfectly for me, but it does not generate the expected result. According to the example, to the Height column I added the label "deu in one year or less fixed rate" which is what I want to appear in the name of the variable , but I still get Height,

 

Herrera524_0-1694553244025.png

 

Herrera524_1-1694553285987.png

How can I make the label appear instead of the name?

 

 

PaigeMiller
Diamond | Level 26

Changing a label does not change the variable name.

 

However, when you do a PROC PRINT with the LABEL option, then the label appears on the output, the variable name does not appear.

--
Paige Miller
Reeza
Super User

@Herrera524 wrote:

Hi
The code works perfectly for me, but it does not generate the expected result. According to the example, to the Height column I added the label "deu in one year or less fixed rate" which is what I want to appear in the name of the variable 

 


Where do you want that name change to appear? 

SAS has variable name limits but you could change it to something less than 32 characters with spaces. I wouldn't recommend doing that because then you have to type it out, but it's doable.

 

option validvarname = any;

data class;
set sashelp.class;
rename height ='Height in inches'n; *note the n at the end to specify a variable name;
run;

VALIDVARNAME=ANY

allows any characters in DBMS column names to appear as valid characters in SAS variable names. Symbols, such as the equal sign (=) and the asterisk (*), must be contained in a 'variable-name'n construct. You must use ANY whenever you want to read DBMS column names that do not follow the SAS naming conventions.

Up to 32 characters are allowed in a column name.

Any column name that is not unique when it is normalized is made unique by appending a count (0, 1, 2, and so on).

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0vnyuzncldjabn1923ug8svx7uh.htm

 

 

Herrera524
SAS Employee

 

Where do you want that name change to appear? 

 

It is for a report that I am creating and I need that name to appear in it. Thank you very much for your support

 

I'm going to use what you shared with me.

PaigeMiller
Diamond | Level 26

@Herrera524 wrote:

 

Where do you want that name change to appear? 

 

It is for a report that I am creating and I need that name to appear in it. Thank you very much for your support

 

I'm going to use what you shared with me.


Every reporting procedure in SAS allows you to use labels instead of the variable name when it produces a report. In PROC PRINT, the LABEL option is needed. In PROC REPORT, labels are used automatically. In PROC TABULATE, I don't know if labels are used automatically.

--
Paige Miller
Reeza
Super User

If it's for a report, labels should be sufficient. If you can produce a reprex (basic reproducible example) someone can show you how labels can be utilized in that report, for example proc report, tabulate, freq. Labels are definitely the better solution as they don't have the 32 character limit like the variable name.

 

 

PaigeMiller
Diamond | Level 26

The whole point of labels is that it allows you a lot more freedom to provide text to describe a variable than the variable name allows; it is also much more convenient to put this text into the variable label, not the variable name. As @Reeza points out, if you want that long text string as the variable name, that's a lot to type each time you want to use this variable (and don't make a spelling error!)

 

Almost all SAS procedures allow you to use the label in the output. So, there may be rare cases (emphasis on rare) where labels don't do the job, but really, in virtually every case I can think of, this text ought to go in the label and not the variable name.

--
Paige Miller

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 25. 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
  • 10 replies
  • 2608 views
  • 3 likes
  • 3 in conversation