How can I output a certain number of observations satisfying a where statement in SAS

Rikesh Punja

For example I want to output only the first 5 observations in the table CARS which satisfies the WHERE statement that Horsepower is greater than 265.

DATA test(obs=5);
SET SASHELP.CARS;
WHERE Horsepower > 265;
RUN;

The above doesn't work. This seems very simple but I'm not sure how to achieve what I want here.

Stu Sztukowski

Use if(_N_ > 5) then stop.

data want;
    set sashelp.cars;
    where horsepower > 265;
    if(_N_ > 5) then stop;
run;

Or, use SQL outobs

proc sql outobs=5;
    create table want as
        select *
        from sashelp.cars
        where horsepower > 265
    ;
quit;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to count the number of observations in a SAS table?

where do i add an if statement into my program to find a certain number

How can I download all observations from Hue/Hive output?

Data manipulation - how can I count the number of observations for multiple variables?

How can I add a SUM clause for a certain variable to a WHERE statement in SQL Server

How do i extract certain values in a row satisfying a condition in a dataframe?

How to create an output with the number of observations in each row?

How can I combine VLOOKUP within an IF statement where the column index of the VLOOKUP function is a number extrapolated from a text?

How can I reduce the number of conditions in a statement?

How to run part of macro based on number of observations in work file in SAS

How can I mutate a column to returns a value if all observations of a certain level have the same value?

Is there a way to count the number of columns satisfying a certain condition?

In R, how can I count the number of observations and the number of groups in which they occur?

How can I declare a variable ($output) with the output within an IF -Statement?

How can I count elements satisfying a condition in a group, with PostgresSQL

How can I get the values satisfying some conditions in a dataframe

R- How can I update column values only pertaining to rows where column contains beginning of a certain number?

How can I maintain consistent box width in a boxplot where factor*group combination has no observations?

Dropping observations after a certain condition is met in SAS

In data.table, How can I subset with ifelse() in j and use .N as the number of observations after the subset?

How can i get R to count the number of observations in a dataset which fall under a category defined in another dataset

How can I sort the output of awk, disregarding a certain character?

How can I omitt certain lines from an Nmap output scan?

How can I name the output of a compiled source file in a certain way?

how can I output a certain text from a file in c?

Where and how can I get a certain version of NodeJs?

How can I find where certain bash function is defined?

How can I count the number of rows that are not zero in a certain range in python?

How can I check if a variable is less then a certain number in ejs