proc sql;
create table a as
select rank,
pos_id,
c_estado,
d_estado,
c_cartao_sup,
c_ndc_sup,
c_orgao_resp
from (select row_number() over (partition by pos_id order by c_estado asc, c_cartao_sup desc) as rank,
pos_id,
c_estado,
d_estado,
c_cartao_sup,
c_ndc_sup,
c_orgao_resp
from f_agreg_mens_pos)x
where rank=1;
run;
Editor's Note: The title was changed to more generally reflect the goal.
Try this:
proc sort data=f_agreg_mens_pos;
by pos_id c_estado descending c_cartao_sup;
run;
data want;
rank = 1;
set f_agreg_mens_pos;
by pos_id;
if first.pos_id;
keep
rank
pos_id
c_estado
d_estado
c_cartao_sup
c_ndc_sup
c_orgao_resp
;
run;
If I read that code correctly, you want the top observation according to the sort order.
See if you can use the 'translation' in the example below by converting to subqueries
https://stackoverflow.com/questions/43191746/sql-to-proc-sql-partition-by-alternative-min-case
Hi, I can not translate by converting to subqueries, it's confused. There is no way to do row_number() over (partition by ) in SAS Studio?
Try this:
proc sort data=f_agreg_mens_pos;
by pos_id c_estado descending c_cartao_sup;
run;
data want;
rank = 1;
set f_agreg_mens_pos;
by pos_id;
if first.pos_id;
keep
rank
pos_id
c_estado
d_estado
c_cartao_sup
c_ndc_sup
c_orgao_resp
;
run;
If I read that code correctly, you want the top observation according to the sort order.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.