BookmarkSubscribeRSS Feed
jonty
Fluorite | Level 6

 

 

 

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;

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 814 views
  • 0 likes
  • 2 in conversation