Create a copy of a dataset in sas
If you are running SAS PC (or any form of SAS) you will likely have a table that you want to make a copy of. Perhaps with your new copy you will want to exclude certain records or add new fields. Below are some examples that will help you achieve these tasks.
It is good to remember that with in SAS, your default library is Work. So any new datasets / tables that you create through your program will go to work by default unless you prefix your dataset name / table name with the name of the library you wish to operate in.
Making a copy of an existing dataset in SAS
Example (assuming the dataset is in your work lib and want a copy of it in your work lib):
DATA existingDataSet;
SET copyOfDataSet;
RUN;
As mentioned before, by default the copy of the existing data set will be placed in your work library.
Example 2 (take existing dataset (ds) from work library and place in lib DataMine):
DATA existingDataSet;
SET DataMine.copyOfDataSet;
RUN;
Now your the new table, copyOfDataSet, will be for use in your library DataMine.
Filtering the records in your new data set (i.e. setting parameters).
What if you wanted to set some parameters? Let's say for example that you only wanted records with rec_id greater than 100 (assuming you have the field rec_id in your data set.
DATA existingDataSet;
SET DataMine.copyOfDataSet(WHERE=(rec_id GE 100));
RUN;
The new data set resulting data set "copyOfDataSet" will now be created will all records that have a rec_id greater than or equal to 100 in your library DataMine. To create it in your work librarly, simply replace DataMine with the word "Work" or delete the library reference completely.
Adding a new field/variable to your new SAS dataset/table
Let's go a step further and add a variable to our new sas dataset
DATA existingDataSet;
SET copyOfDataSet(WHERE=(rec_id GE 100));
RUN;
Our new dataset now consists of records with rec_id greater than or equal to 100 and it has a new text field named newTextVar with 50 characters of available space. The max I believe is 5000 characters.
That concludes the the mini lesson in creating copies of existing SAS datasets/tables.