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.

 

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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