I have to create a library.
Then, I have a data called chemistry with 3 variables (name, gender, year_of_birth).
I have to input all the obs and the 3 variables into a new dataset called chemistry_new and store it in the library.
Also, I need to add a new variable named age.
The age variable is the number of years between the student's year of birth and year 2010 (e.g., if y_o_b=1990, then age=2010-1990=20).
So far I have done this but it seems to be wrong..
libname libref "C:\myfolders";
data chemistry_new;
set sasdata.chemistry;
input name $ gender $ year_of_birth;
age = 2010-year_of_birth;
run;
There are a few issues here. First, what folder holds the existing data set called chemistry? Is it C:\myfolders ? If so, you would need this statement in your program to identify where the data is coming from:
libname sasdata "C:\myfolders";
After that, sasdata.chemistry would be the proper way to refer to the existing data set.
Second, what folder do you want to use to store your new data set? If it is going to be the same folder, you would need to identify the new data set as:
data sasdata.chemistry_new;
If it is going to be some other folder, you need to add an additional LIBNAME statement to identify that other folder.
Finally, since chemistry is already a SAS data set, SAS knows all the variables it contains. You don't need an INPUT statement to define them. Just remove the INPUT statement.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.