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

I want to show some specific obs from a dataset with Proc Print

Ex-- we have a dataset which contains name with different Genders.

Name     Gender

 

X            M

Y            M

Z            F

A            M

 

I want to print only Gender = M obs with Proc Print, we can use Where condition.But if i don't want to print all obs but some specific number (For Ex-2 -- only x and Y not Z)   

How to do it?

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Why not simply

proc print data=have(where=(gender='M') obs=2);
run;

or equivalently

proc print data=have(obs=2);
where gender='M'; 
run;

 

 

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18
data temp;
set have(where=(gender='M'));
run;
proc print data=temp (obs=2); var <list of variables to print>; run;
FreelanceReinh
Jade | Level 19

Why not simply

proc print data=have(where=(gender='M') obs=2);
run;

or equivalently

proc print data=have(obs=2);
where gender='M'; 
run;

 

 

andreas_lds
PROC Star

Maybe you need to write down the rules an observation has to fulfil to be printed.

s_lassen
Meteorite | Level 14

If you want the first n observations of a specific subset, it is much easier to use SQL with the OUTOBS option:

Proc sql outoubs=20;
  select name from have where gender='M';
quit;

You may want to use ORDER BY to make sure you get the topmost observations, SQL does not guarantee the order otherwise.

SuryaKiran
Meteorite | Level 14

Are you trying to control the number of records to print or you want to print the list of record that you wish?

If you have a list where your print result need to include from then, Why not list them in where condition. Create a list of values into a macro and then later filter them in Proc print where condition.

 

proc sql noprint;
select quote(strip(name)) into:names separated by ','
from sashelp.class
where age>13;
quit;

proc print data=sashelp.class(where=(sex='M' and name in (&names.)));
run;

 

Thanks,
Suryakiran

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 6174 views
  • 0 likes
  • 6 in conversation