BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
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.
4 REPLIES 4
ballardw
Super User
> 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.
piggy
Fluorite | Level 6
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
R_A_G_
Calcite | Level 5
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
R_A_G_
Calcite | Level 5
Thank you all

ballardw suggestion worked I actually used this:

data new_data (keep=A1 A2 A3);
set old_data (OBS=35);
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 836 views
  • 0 likes
  • 3 in conversation