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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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