Senior User
Posts: 1

# extract column names and then apply arithmetic function if all the criterias are met

My data set looks like this

10001_t      10001_C1   10001_C2  10001_C3  10001_C4    10002_t      10002_B1   10001_B2    10001_B3

value1          value2        value3        value4        value5          value6         value7        value8          value9

value10        value11      value12      value12      value14        value15       valu16        value17        value18

value19        value20      value21      value22      value23        value24       valu25        value26        value27

value28        value29      value30      value31      value32        value33       valu34        value35        value36

Now, I want to  divide all the values in 10001_C1 with values in 10001_t , similarly all values in column 10001_C2 will be divided by 10001_t ( which is like the total for that 'C' group, here 10001_C1 is considered as C group) . Division will take place till 10001_C4 column after that the denominator will change ( i.e earlier it was value2/value1 , value3/value1, value4/value1, value5,value1). Now everytime the column name had 't' at the end the denominator will change so when 10002_t comes the denominator will be value_6, so the new table will have percent value in 10002_B1 column as value7/value6, the column 10001_B2 will have vlaue8/value6 and 10001_B3 will have value9/value6.

I know its a bit confusing but it's all I have and would really appreciate if someone can suggest  a way to solve it. I don't mind if we divide in same table or create a new one. Also the data set is quite big so the code has be dynamic. will really appreciate any help I can get.

Thanks

PROC Star
Posts: 1,555

## Re: extract column names and then apply arithmetic function if all the criterias are met

Hi, Thank you for your question. May i request you to provide sample data that would help to have something to work with and test please?

If you could please provide the community with a sample input data and a sample of expected output data so that you and the community can test/validate.

Thank you

Super User
Posts: 13,292

## Re: extract column names and then apply arithmetic function if all the criterias are met

Since your column names by default are not valid SAS variables show us what the variable names in your SAS data set actually are.

Pick a couple variables, show us actual values and what the actual desired output for those values looks like. Real actual numeric non-trivial (not all 1 or 2) numbers.

Discussion stats
• 2 replies
• 64 views
• 0 likes
• 3 in conversation