Hi, I am using the YRBS dataset. I'd like to create a new table with just a few columns from an existing dataset.
Here is my current code, which does *not* work:
data work.yrbs2007 (Keep = Age Sex Grade RaceEthnicity Inclusion Survey_Year Sunscreen_Binary BMICategory); run;
How do I create a new table (let's call it work.yrbs2007mod) from my existing datatable (work.yrbs2007) with a few selected columns (Age Sex Grade RaceEthnicity Inclusion Survey_Year Sunscreen_Binary BMICategory)?
Thanks so much! 🙂
The name that goes on the DATA statement is the name of the NEW dataset.
You would put the name of the OLD dataset on the SET statement. What is the name of the current YBRS dataset? Let's assume it is named YRBS2007 and it is in the directory that you pointed the MYLIB libref towards.
Then your could should look like:
data my_subset;
set mylib.yrbs2007;
keep Age Sex Grade RaceEthnicity Inclusion Survey_Year
Sunscreen_Binary BMICategory
;
run;
For your problem description you should not need to add any dataset options on the output dataset name. In fact there is probably no need to use dataset options at all.
It might be a tiny bit more efficient to use a KEEP= dataset option on the source dataset read by the SET statement. But it probably is not really worth making the code more complicated just to do that.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: