BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DangIT
Fluorite | Level 6

Hi,

I'm stuck on something very simple..

I have a data step with an array that recodes a numeric into category variables, and i would like to add the text of the variable being coded as a prefix into the value of the category.

For example:

This is the code i am working with:

Data Table1 ; Set Data ;

Array num{*} var1 var2 var3 ;

Array Cat{*} cat1 cat2 cat3 ;

do i=1 to dim(num) ;

     IF num{i} LE 50 then cat{i}='0-50';

     IF num{i} GE 50 then cat{i}='0-100';

end ;

run ;

From this I get 3 category variables with 2 values '0-50' and '0-100'.

Cat1:  '0-50' and '0-100'

Cat2:  '0-50' and '0-100'

Cat3:  '0-50' and '0-100'

Essentially what I would like to do is add the prefix of num{i} into the value so it would look like:

Cat1:  'var1: 0-50' and 'var1: 0-100'

Cat2:  'var2: 0-50' and 'var2: 0-100'

Cat3:  'var3: 0-50' and 'var3: 0-100'

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try:

Cat{i} = catx(':',vname(num{i}),'0-50');

Cat{i} = catx(':',vname(num{i}),'0-100');

View solution in original post

3 REPLIES 3
ballardw
Super User

Try:

Cat{i} = catx(':',vname(num{i}),'0-50');

Cat{i} = catx(':',vname(num{i}),'0-100');

DangIT
Fluorite | Level 6

Perfect, thank you, I didn't know the vname function existed.

Reeza
Super User

Check your boundary conditions, you have GE 50 and LE 50, so where do you really want 50 to end up?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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