BookmarkSubscribeRSS Feed
ronaldo7
Calcite | Level 5

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! 🙂

1 REPLY 1
Tom
Super User Tom
Super User

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.

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 139 views
  • 0 likes
  • 2 in conversation