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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 776 views
  • 0 likes
  • 3 in conversation