BookmarkSubscribeRSS Feed
gotchj1
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.

gotchj1_0-1683423586574.png

gotchj1_1-1683423607018.png

 

 

2 REPLIES 2
ballardw
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'
;
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.

mkeintz
PROC Star

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.

 

--------------------------
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

--------------------------

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
  • 2 replies
  • 716 views
  • 0 likes
  • 3 in conversation