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.
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' ;
run;
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. ; run;
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.
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' ;
run;
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.