Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the 1st occurrence of Sex (male & female both) from sashelp.class

I am trying to get all the details in a row for the first occurence of sex=’m’ and sex=’f’ from sashelp.class.

Sex is a column in sashelp.class

Till now I have done this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Proc sql;
Select *
From sashelp.class
Where sex='m' or sex='f'
Order by sex
Limit 1;
Quit;

This gives me an error in the limit statement. Saying "Syntax Error, expecting on of the following: !, !! … etc"

>Solution :

Here is an easy to follow data step approach.

data want;
   set sashelp.class;
   if sex = 'M' and m = . then do;
      output; m = 1; 
   end;
   if sex = 'F' and f = . then do;
      output; f = 1; 
   end;
   retain m f;
   drop m f;
run;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading