i have a data where AON is having multiple entries. i fond entries which have MAX(AON) and created a table.
then i wish to append the new and orriginal file but hard luck.
anyhelp guys....
CODE :-
proc sql;
create table ans_4B as select* from work.import
group by PRODUCT_ID
union
select PRODUCT_ID , MAX_AON from work.ans_4A;
quit;
Please elaborate on what does not work, provide test data in the form of a datastep in the post (use the {i} to preserve formatting) and what the output should look like.
At a guess from the minimal info you provided:
Union appends one dataset to another asumming that both have the same variables. This is presumably not the case as you select * from the first, and select 2 variables in the second which is unlikely to be the same. Also, you do not group by like, it wouldn't do anything to the data, but is pretty much invalid in that sense.
If you want just to add the largest:
proc sort data=imp out=max_imp nodupkey; by product_id descending aon; run; proc append base=imp data=max_imp force; run;
Or you could just do it in one datastep, retain the aon each row by product_id and at the end of the group output twice:
data want; set imp; by product_id; retain max_aon; if first.product_id then max_aon=aon; else if aon > max_aon then max_aon=aon; if last.product_id then do; output; aon=max_aon; product_id=cat(product_id," ","Max"); output; end; else output; run;
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.