turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- subsectioning the data

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-08-2011 11:56 AM

Hello,

I have two related problems.

1) I have a data set with 100 observation I only need the first 15 of them.

2) next only need 5 variables of the 14 variables

I used KEEP statement but my data came out with the wrong order. These are binary data and I need to keep the order the way it was in the original data.

Thanks

R.A.G.

I have two related problems.

1) I have a data set with 100 observation I only need the first 15 of them.

2) next only need 5 variables of the 14 variables

I used KEEP statement but my data came out with the wrong order. These are binary data and I need to keep the order the way it was in the original data.

Thanks

R.A.G.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-08-2011 04:34 PM

> Hello,

>

> I have two related problems.

>

> 1) I have a data set with 100 observation I only need

> the first 15 of them.

on the set statement ( or just about anywhere you have a DATA= use the OBS= option

Data newdata;

set olddata (obs=15);

run;

Also look at FIRSTOBS.

>

> 2) next only need 5 variables of the 14 variables

>

> I used KEEP statement but my data came out with the

> wrong order. These are binary data and I need to keep

> the order the way it was in the original data.

Which order? Sort, as in row order, or columns in a dataset. If the latter I wouldn't worry about as other applications that may want the data would either link to the variable name or when you export the data then specify the column order.

>

> I have two related problems.

>

> 1) I have a data set with 100 observation I only need

> the first 15 of them.

on the set statement ( or just about anywhere you have a DATA=

Data newdata;

set olddata (obs=15);

run;

Also look at FIRSTOBS.

>

> 2) next only need 5 variables of the 14 variables

>

> I used KEEP statement but my data came out with the

> wrong order. These are binary data and I need to keep

> the order the way it was in the original data.

Which order? Sort, as in row order, or columns in a dataset. If the latter I wouldn't worry about as other applications that may want the data would either link to the variable name or when you export the data then specify the column order.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-09-2011 04:10 AM

you can use retain to reorder your variables

data new (keep=name height weight);

retain height weight name;

set sashelp.class;

run; Message was edited by: piggy

data new (keep=name height weight);

retain height weight name;

set sashelp.class;

run; Message was edited by: piggy

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-09-2011 10:40 AM

Thank you for the suggestions.

but I want to keep the same order (sort) as the original data. my problem is that once I KEEP the desired variables they get sorted by the KEEP variables.

thanks

but I want to keep the same order (sort) as the original data. my problem is that once I KEEP the desired variables they get sorted by the KEEP variables.

thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-09-2011 11:20 AM

Thank you all

ballardw suggestion worked I actually used this:

data new_data (keep=A1 A2 A3);

set old_data (OBS=35);

run;

ballardw suggestion worked I actually used this:

data new_data (keep=A1 A2 A3);

set old_data (OBS=35);

run;