- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc sort data =emp;by descending EmpSal ;run;
data emp_1;
set emp;
cnt +1;
if cnt = 1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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