ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.


Hi All,

I want to find the maximum value of observation from a variable using data step only.

we can not use any procedures and END option for data step.

Example :

EmpID      EmpSal     EmpName

E001          5000          A         

E002          7500          B    

E003          2500          C

E004          9800          D         

E005          6100          E

I am looking for the maximum salaried EmpID / EmpName or whatever which should contain maximum value from a variable.

Regards

Uma Shanker

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

No procedures at all, and no END= on the DATA step:

data want;

   set have nobs=_nobs_;

   if EmpSal > max_EmpSal then do;

     max_EmpSal = EmpSal;

     max_EmpID = EmpID;

     max_EmpName = EmpName;

   end;

   retain max_:;

   keep max_:;

   if _n_ = _nobs_;

run;

Why in the world do you have these restrictions?

View solution in original post

6 REPLIES 6
LinusH
Tourmaline | Level 20

What's up with the phony restrictions on PROC's? Is this a part of your training?

To solve this in the data step, use RETAIN.

Data never sleeps
TarunKumar
Pyrite | Level 9

proc sort data =emp;by descending  EmpSal ;run;

data emp_1;

set emp;

cnt +1;

if cnt = 1;

run;

Astounding
PROC Star

No procedures at all, and no END= on the DATA step:

data want;

   set have nobs=_nobs_;

   if EmpSal > max_EmpSal then do;

     max_EmpSal = EmpSal;

     max_EmpID = EmpID;

     max_EmpName = EmpName;

   end;

   retain max_:;

   keep max_:;

   if _n_ = _nobs_;

run;

Why in the world do you have these restrictions?

umashankersaini
Quartz | Level 8

Hi,

Thanks to all for your quick response, specially to "Astounding".

It's not all about the training and restrictions. It's only to explore the new ways to finalize the required output but yes it is something to learn in a limited bowl of resource and knowledge or may be sometime with restrictions.....

I am highly thankful for all answers...

Regards

Uma Shanker Saini

Haikuo
Onyx | Level 15

Here is another approach using Hash in data step, and it is one of a few times that Hash is not as twice  verbose as conventional data step.

data _null_;

if 0 then set have;

  declare hash h(dataset:'have', ordered:'d' , multidata:'y');

  h.definekey('EmpSal');

  h.definedata(all:'y');

  h.definedone();

  h.output(dataset:'want(obs=1)');

run;

Haikuo

umashankersaini
Quartz | Level 8

Hi Hai.Kuo / Ksharp,

I am not much familiar with Hash.

would any one love to provide me good stuff ( online path or pdf ) so that i can learn.

email : umashankersaini@yahoo.com

Regards

Uma Shanker Saini

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 7602 views
  • 5 likes
  • 5 in conversation