BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
evanwarrenqu
Calcite | Level 5

Hi Everyone,

 

I'm looking to sum two variables ('arrivals' and 'departures') into one new variable ('total_activities').

The data set contains about 15,000 rows and I have four datasets to work with, so I wasn't sure if there was a way to do this without using codes and cards?

I can always add a new column in excel and re-import the data, but I was hoping to avoid that.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Capt_VA_SAS
SAS Employee

If you want to save your file to a permanent location, you will need to setup what we call a SAS library.
After you set this up, you can refer to it and save your files to that location.

 

libname MYDATA 'C:\some_file_folder_location' ; 

data mydata.nycw;
set work.nycw;
total_activities = sum(arrivals, departures);
run;

 The only thing I can't tell you is where your data is currently residing.  It is on your computer and SAS is referencing it, so it must have a library name associated with it.  If you haven't already explicitly listed the library then it is either in a temporary library created during the import or it is in WORK.  WORK is not a permanent library and will be purged once you close SAS.

 

 

View solution in original post

6 REPLIES 6
Capt_VA_SAS
SAS Employee

Hi Evan,

A quick way to do this would be to create a new column using data step code below.

You could add the two columns using a '+' sign or using the SUM function.  Using the '+' sign will return a missing value when one of the inputs is missing.  Using the SUM function will implicitly impute the missing into a zero and you will get an answer.

 

 

data work.updated_data;
set work.original_data;
   total_activities = sum(arrivals, departures);
run;

 

evanwarrenqu
Calcite | Level 5

Great thanks! And just so I know, should I replace the work.original_data with my dataset?

The original dataset is named "NYCW"

Capt_VA_SAS
SAS Employee
That is entirely up to you, but I wouldn't replace the original data until I am absolutely sure that I have no other changes to make. Once you overwrite the original, there's no going back.
evanwarrenqu
Calcite | Level 5

Sorry, bad wording on my part in the question there 🙂

What I meant was when I put the code in, should it read:

data work.updated_data;

or

data NYCW.updated_data;

and same for work.original_data or NYCW.original_data

Capt_VA_SAS
SAS Employee

If you want to save your file to a permanent location, you will need to setup what we call a SAS library.
After you set this up, you can refer to it and save your files to that location.

 

libname MYDATA 'C:\some_file_folder_location' ; 

data mydata.nycw;
set work.nycw;
total_activities = sum(arrivals, departures);
run;

 The only thing I can't tell you is where your data is currently residing.  It is on your computer and SAS is referencing it, so it must have a library name associated with it.  If you haven't already explicitly listed the library then it is either in a temporary library created during the import or it is in WORK.  WORK is not a permanent library and will be purged once you close SAS.

 

 

evanwarrenqu
Calcite | Level 5

Perfect that's what I needed, thank you so very much!

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 choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 24480 views
  • 0 likes
  • 2 in conversation