BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aarony
Obsidian | Level 7

    i want o keep first 5 lines of the data and delete everything else. how may i do so using the data want; set have; run; ?

many thanks,

aaron

1 ACCEPTED SOLUTION

Accepted Solutions
arodriguez
Lapis Lazuli | Level 10

Hi Aaron,

you can use the _N_ variable. This variable is the row nuber that appears at the left in the dataset visualisation. To keep the first 5 only must do

data want;

set have;

if _N_<=5;

run;

Keep in mind that a where doesn't work with _N_.

View solution in original post

3 REPLIES 3
arodriguez
Lapis Lazuli | Level 10

Hi Aaron,

you can use the _N_ variable. This variable is the row nuber that appears at the left in the dataset visualisation. To keep the first 5 only must do

data want;

set have;

if _N_<=5;

run;

Keep in mind that a where doesn't work with _N_.

Haikuo
Onyx | Level 15

While you already have the correct answer, but as they always say, SAS has 6 solutions for every problem Smiley Happy,

To avoid read in all of the data, you could do:

1. Stop reading when it is time,

Date want;

set have;

if _n_ >5 then stop;

run;

2. Just bring in 5:

Date want;

set have (obs=5);

run;

Good luck with your homework,

Haikuo

aarony
Obsidian | Level 7

Thank you so so much both!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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