BookmarkSubscribeRSS Feed
sasq
Calcite | Level 5

I have various values for different variables in mutiple rows and columns showing 0/2 or 0/3 or 0/4 and so on ..

I have a total of 7 columns depicting treatmentand they have values like "0/some numeral"

I was to assign these values a "0" value. Can anyone please tell me how do i do this?

I can try to use index but for multiple row and multiple column it is not reading.

 

 

5 REPLIES 5
LinusH
Tourmaline | Level 20
Test if the first position is a 0 then assign it to 0.
You can use an array to reuse that code.
Data never sleeps
sasq
Calcite | Level 5

Thankx for the responce. It is not the first position.  i have 200 rows and 7 columns and these values come randomly as 0/some numeral.. So i do not know how to assign them in such scenario.

ballardw
Super User

Show some example data and the desired result.

sasq
Calcite | Level 5

Thankx for reaching out.

The data looks like

 

trta_1 trta_2 trta_3 ,trtb_1 trtb_2  trtb_3 wher trta and trtb are different drugs

 trta_1 and trta _2 are two different time points of the same drug.

trta_3 will be the sum of same drug at the different  time point.

 

trta_1 trta_2 trta_3    trtb_1 trtb_2  trtb_3

1/5     0/5       1/5        7/5      0/5     7/5

Astounding
PROC Star

Well, you don't tell us the names of the variables, so I will call them COL1 through COL7.

 

This is the way you would correct a single variable:

 

if col1 =: '0/' then co1='0';

 

This assumes that '0/' would appear at the beginning of the variable's value.  If that's not the case, it can be done but becomes more complex.

 

To apply the same logic to all 7 variables, you would use an array:

 

array cols {7} col1-col7;

do _n_=1 to 7;

   if cols{_n_} =: '0/' then cols{_n_} = '0';

end;

 

Good luck.

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
  • 5 replies
  • 1620 views
  • 0 likes
  • 4 in conversation