BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I am running merge in proc sql.

I have Where+Rename+IN  statements .

I get an error so I think that the order of  them is not correct

What is the correct order of   Where+Rename+IN options in merge?

What is the logic of the correct order? IS there order of actions?

 

PROC SQL;
	create table output as
	select 	a.*,b.*   
	from AllModels(where=(_TYPE_=3)in=a ),
         AllModels(where=(_TYPE_=0)  rename=(Obligo=TotalObligo )in=b) 
;
QUIT;

 

 

2 REPLIES 2
Kurt_Bremser
Super User

in = dataset options are only valid in data steps.

What you are looking for in SQL are table aliases:

proc sql;
create table output as
select
 a.*,b.*   
from
  AllModels (
    where=(_TYPE_=3)
  ) as a,
  AllModels (
    where=(_TYPE_=0)
    rename=(Obligo=TotalObligo)
  ) as b 
;
quit;

Note that this SQL willl create a cartesian product (the target dataset will have (nobs of AllModels) ** 2 observations).

It will also create a NOTE or WARNING for columns already present.

Could it be you are looking for a vertical stacking of datasets? That would best be achieved with a simple data step.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please differentiate what is SAS syntax and what is SQL syntax.  Whilst you can use some dataset options in SQL, it really isn't recommended.  

proc sql; 
  create table output as
  select a.*,
         b.obligo as totalobligo   
  from   (select * from allmodels where _type_=3) a,
         (select * from allmodels where _type_=0) b;
quit;

Do note a few things also, select * from multiple tables will cause you issues.  The principal is that you should know your data, know what it contains, and what you want in the output.  

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 2 replies
  • 961 views
  • 0 likes
  • 3 in conversation