BookmarkSubscribeRSS Feed
saskishore
Calcite | Level 5
Proc sql,
    create table test1 as 
    select m1,f,1,l1,np1
    from table k.claimtable a
    inner join k.tab2 b,
    ON(a.m1=b.m1)
    where a.pc in ('1234')
a.ser_date between '01jan2022'd and 31aug2022'd
order by a.ser_date ;


Proc sql, create table test1 as select m1,f,1,l1,np1 from table k.claimtable a inner join k.tab3 b, ON(a.m1=b.m1) where a.pc in ('99999')
a.ser_date between '01jan2022'd and 31aug2022'd
order by a.ser_date ;

 we are joining proc sql's with two different tables (tab2,tab3) with 1 claims table to extract data for those procedure codes.

3 REPLIES 3
ballardw
Super User

Example data of each of the input data set and expected result.

 

Also suggest that you check your syntax for the shown code. You have a , where there should be ; in the Proc statement,

the comma before the ON is questionable, I suspect you are missing an "AND" in the where clauses and the Order by a variable not on the select will cause notes in the log.

 

The bit where both Proc SQL create the same data set, Test1, may also be a bit of an issue as I'm not sure what you expect after running this code.

Tom
Super User Tom
Super User

Show some example input data and the results you want from that input.

You are not saying where the selected variables are coming from.  Which ones are coming from CLAIM and which are coming from TAB2 or 3?

 

Are you looking for something like this?

select a.m1
   /*   , other variables from A */
        , coalesce(b.xxx,c.xxx) as xxx
   /*  Repeat for other variables that could come from TAB2 or TAB3 */
from claimtable
(where=(ser_date between '01JAN2022'd and '31AUG2022'd
       and pc in ('1234','99999')
)  a
left join tab2 b on a.m1=b.m1 and a.pc = '1234'
left join tab3 c on a.m1=c.m1 and a.pc = '99999'
;
PGStats
Opal | Level 21

My best guess:

 

Proc sql;
    create table test1 as 
    (select a.ser_date, m1, f, 1 as aNumber, l1, np1
    from table k.claimtable as a
    inner join k.tab2 as b on a.m1 = b.m1
    where a.pc in ('1234') and a.ser_date between '01jan2022'd and 31aug2022'd)
	union all
	(select a.ser_date, m1, f, 1 as aNumber, l1, np1
    from table k.claimtable as a
    inner join k.tab3 as b on a.m1 = b.m1
    where a.pc in ('99999') and a.ser_date between '01jan2022'd and 31aug2022'd)
	order by ser_date;
quit;
PG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 299 views
  • 0 likes
  • 4 in conversation