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
Jade | Level 19

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.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
  • 5 replies
  • 6945 views
  • 0 likes
  • 6 in conversation