Learning SAS? Welcome to the exclusive online community for all SAS learners.

increment the values in data which are lesser than 65

Reply
New Contributor
Posts: 3

increment the values in data which are lesser than 65

I have a dataset that looks like following:-

ID	Test_1	Test_2	Test_3	Test_4	Test_5
SH101	90.5	   88.4	  92.3	  95.1	   90.0
SH102	64.3	   64.6	   77.4	  72.3	   71.1
SH103	68.1	   69.4	   80.6	  75.4	   70.5

I want to increment values that are less than 65 to just above 65(say 65.01). 

Please help me get this, I have no clue by what method we can increment this.

 

Thanks in advance!

Super User
Super User
Posts: 8,289

Re: increment the values in data which are lesser than 65

Posted in reply to mdhtrivedi

Do you want to convert all values that are less than or equal to 65.01 to 65.01?  

Why not use the MAX function?

 

Occasional Contributor Kow
Occasional Contributor
Posts: 15

Re: increment the values in data which are lesser than 65

[ Edited ]
Posted in reply to mdhtrivedi

I suspect you are getting confused by an array. And arrays can be confusing.

 

You need to test each value to see if it is greater or less than your

cutoff (65.0).  If it is less than 65 than you want to change the value to 65.01

 

If given a variable TEST_1 and you want to do this test you would simply do this :

 

if TEST_1 < 65 then TEST_1 = 65.01;

 

You could repeat this statement for test_1, test_2, etc. over the entire data.

 

Instead of variable names you can use the array references if you declared this in an array (and that is how it looks)

 

A loop works great for this:

 

data youchanged ;

   set yourdata ;

    array test_[5] test_1 test_2 test_3 test_4 test_5 ;

     do i = 1 to 5 ;

 

        if . < TEST_[i] < 65 then do ;  /**I ignore missing values they remain as missing values**/

          TEST_[i] = 65.01     ;

        end ;

 

     end ;

 

I think you can drop inner loop and just have : 

 

if . < var[i] < 65 then var[i] = 65.01     ;

 

You could also do this kind of test before you load the data to the array

 

Do you have missing values?  These will test as <65 so the missing value would become 65.01 as well. Consider what is wanted.

 

A quick reference on using Do loops with arrays.

 

http://support.sas.com/resources/papers/proceedings10/158-2010.pdf

       

 

New Contributor
Posts: 3

Re: increment the values in data which are lesser than 65

Thanks for the response and sorry for late reply. I tried your mentioned
solution but I could find that it creates new columns of test_1 and so on.
Whereas I dont want any replica of columns.
Ask a Question
Discussion stats
  • 3 replies
  • 133 views
  • 0 likes
  • 3 in conversation