Help using Base SAS procedures

quick manipulation of dataset

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 79
Accepted Solution

quick manipulation of dataset

Hi, I have a fairly simple question.

I have a dataset say A

A looks like the below

a    h      j

1    0.5  0.6

0.3  1   0.7

0.3  0.9  1

I would like to subtract a number from each entry of A [ lets say subtract 1 from A] therefore

Anew looks like

a      h      j

0      -0.5  -0.4

-0.7   0      -0.3

-0.7    0.1    0

Then replace the diagonals of Anew with the diagonals of A therefore Anew looks like below

a      h      j

1      -0.5  -0.4

-0.7    1    -0.3

-0.7   0.1    1

There are only 3 columns but I can have any number of columns

Thanks so much for your help   


Accepted Solutions
Solution
‎04-20-2015 01:51 PM
Trusted Advisor
Posts: 1,631

Re: quick manipulation of dataset

This would be extremely easy to do in PROC IML, if you have it available

Anew=A-1;

Anew2=Anew-diag(Anew)+diag(A);

View solution in original post


All Replies
Solution
‎04-20-2015 01:51 PM
Trusted Advisor
Posts: 1,631

Re: quick manipulation of dataset

This would be extremely easy to do in PROC IML, if you have it available

Anew=A-1;

Anew2=Anew-diag(Anew)+diag(A);

Frequent Contributor
Frequent Contributor
Posts: 79

Re: quick manipulation of dataset

Thanks for your help that is what I used too thought there may be something other than using IML.

Trusted Advisor
Posts: 1,631

Re: quick manipulation of dataset

You could do this in a data step but it's a little messier. Why do it in a data step if you already have something that works?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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