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.
Try:
Cat{i} = catx(':',vname(num{i}),'0-50');
Cat{i} = catx(':',vname(num{i}),'0-100');
Try:
Cat{i} = catx(':',vname(num{i}),'0-50');
Cat{i} = catx(':',vname(num{i}),'0-100');
Perfect, thank you, I didn't know the vname function existed.
Check your boundary conditions, you have GE 50 and LE 50, so where do you really want 50 to end up?
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!
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.