DATA Step, Macro, Functions and more

Subtract two columns and output difference to a new dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Subtract two columns and output difference to a new dataset

Hi,

  I have one dataset with 2 columns. I would like to subtract the two columns and output this difference to a new SAS dataset.  How would I go about doing this?

 

Original Table:

ID, A2017, B2018 

 

 

Desired Table:

B2018 - A2017

 


 

 


Accepted Solutions
Solution
‎11-28-2017 05:14 PM
PROC Star
Posts: 1,340

Re: Subtract two columns and output difference to a new dataset

Posted in reply to JayCompany

why didn't you try the most basic? Not trying to find fault, but these kind of questions may not be appreciated by most solution contributors.

 

data your_wanted_output;

set your_given_input;

new_column_c = column_b - column_a;

keep new_column_c ;

run;

 

View solution in original post


All Replies
Super User
Posts: 6,542

Re: Subtract two columns and output difference to a new dataset

Posted in reply to JayCompany

It's a little difficult knowing where to begin here.  Let's start with assessing what you already have and what you already know.

 

When you say you have a data set, is it already a SAS data set?

 

Do you know how to create a new SAS data set?

 

Do you know how to bring in data from an existing SAS data set?

 

Do you know how to create a new variable?

 

Do you know how to assign that new variable the outcome of a subtraction?

 

The solution will look incredibly simple in retrospect.  I'm just trying to determine how much of it you already understand, so the solution can focus on the rest of the question.

Solution
‎11-28-2017 05:14 PM
PROC Star
Posts: 1,340

Re: Subtract two columns and output difference to a new dataset

Posted in reply to JayCompany

why didn't you try the most basic? Not trying to find fault, but these kind of questions may not be appreciated by most solution contributors.

 

data your_wanted_output;

set your_given_input;

new_column_c = column_b - column_a;

keep new_column_c ;

run;

 

Occasional Contributor
Posts: 8

Re: Subtract two columns and output difference to a new dataset

Posted in reply to novinosrin
You sir, are the man!
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 495 views
  • 0 likes
  • 3 in conversation