- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Great thanks! And just so I know, should I replace the work.original_data with my dataset?
The original dataset is named "NYCW"
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Perfect that's what I needed, thank you so very much!