BookmarkSubscribeRSS Feed
Fluorite | Level 6

Im trying to add labels corresponding to the rank. I provided two csv files that you could upload into sas. I was thinking about using the label function or a proc sql. Any help would be greatly appreciated.





Super User

SAS Labels as created by the Label statement would be column or row heading text, not for each value. So that is not a way to start.


If you do not need to display the rank value a format that translates the numeric (? we don't have YOUR data and importing a different file doesn't mean the result will be the same for values that contain only digits but were actually character) value to any given text for that value.

Proc format;
value myrank
0 ='bottom size'
1 ='middle size'
/* repeat pattern through*/
9 ='t for top-bottom BM'

Then use that format for the Rank variable when desired. For example this will show the formatted value of Rank in proc print.

Proc print data=yoursetname;
    format rank myrank. ;

If you really need another variable then you would use a data step and either an If/then/else block of codes to assign the text to a new variable or use: NewVar = Put(rank, myrank.);  (if you use the shown example code to make the format).


Comment on your content: I would not call that variable "rank" as rank normally relates to assigning an order of similar items such as game scores, prices, or measurements. Your variable rank represents, as far as I can tell 4 different things:

1) order of something called "size"

2) a t-statistic (? and in the wrong column from what I see) for that "size"

3) order for something called "BM"

4) and a t-statistic for "BM"


I can accept that it is an Order variable. I create such moderately often when I need something in a report to appear in a given order that doesn't match any sort order. Use of the work Rank may lead someone to think it means more than you intend.

Jade | Level 19

Labelling a variable would not advance your cause.  You either need to make a new variable containing text, or use a format to label values instead.(i.e. rank=0 displays as "bottom size", 1 as "middle size", etc.).  


Consider creating a format as below.


proc format ;
  value rnktxt
    0='bottom size'
    1='middle size' 
    2='top size'
    3='top-bottom size'
    4='t for top-bottom size'
    5='bottom BM'
    6='middle BM'
    7='top BM'
    8='top-bottom BM'
    9='t for top-bottom BM'   ;

You would need to apply the rnktxt format to the variable rank.   But to demonstrate, please provide your data in the format of a working SAS data step.


The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets




Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3 in conversation