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!
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.
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;
Great thanks! And just so I know, should I replace the work.original_data with my dataset?
The original dataset is named "NYCW"
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
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.
Perfect that's what I needed, thank you so very much!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.