BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WilliamB
Obsidian | Level 7

 

Hello,

I would like to recover the price of table 1, to complete my table 2.

 

In SQL code please.

 

Thanks for your help.

 

Table1   Table2   Want   
            
NotePrice  IDNote  IDNotePrice 
AAA1200  45AAA  45AAA1200 
AA+1100  14AAA  14AAA1200 
AA1000  17BBB  17BBB425 
AA-850  45CCC  45CCC200 
A+775  17AA  17AA1000 
A600  19AAA  19AAA1200 
A-500          
BBB+450          
BBB425          
BBB-400          
BB+375          
BB350          
BB-325          
B+300          
B275          
B-250          
CCC+225          
CCC200          
CCC-175          
1 ACCEPTED SOLUTION

Accepted Solutions
emrancaan
Obsidian | Level 7
DATA HAVE;
infile cards expandtabs ;
input note $  price;
cards;
AAA	1200
AA+	1100
AA	1000
AA-	850
A+	775
A	600
A-	500
BBB+	450
BBB	425
BBB-	400
BB+	375
BB	350
BB-	325
B+	300
B	275
B-	250
CCC+ 225
CCC	200
CCC- 175

;
run;


DATA HAVE1;
infile cards expandtabs ;
input ID   Note $;
cards;
45	AAA
14	AAA
17	BBB
45	CCC
17	AA
19	AAA
;
Run;


Proc SQl;
Create table want as
Select a.ID,a.Note,Price
FROM have1 a inner join have b on a.note=b.note
where a.id in ( Select ID from have1)
;QUIt;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As on your last post, put test data in the form of a datastep, we cannot tell structure nor will we type that in to test things.

Something like:

proc sql;
  create table want as
  select a.*,b.price
  from  table2 a
  left join table1 b
  on a.note=b.note;
quit;

If your learning SQL, then its good to read up on the guidance, and help pages such as:

https://www.w3schools.com/sql/

And:

Capture.PNG

WilliamB
Obsidian | Level 7
thank you very much. I will look at it.
emrancaan
Obsidian | Level 7
DATA HAVE;
infile cards expandtabs ;
input note $  price;
cards;
AAA	1200
AA+	1100
AA	1000
AA-	850
A+	775
A	600
A-	500
BBB+	450
BBB	425
BBB-	400
BB+	375
BB	350
BB-	325
B+	300
B	275
B-	250
CCC+ 225
CCC	200
CCC- 175

;
run;


DATA HAVE1;
infile cards expandtabs ;
input ID   Note $;
cards;
45	AAA
14	AAA
17	BBB
45	CCC
17	AA
19	AAA
;
Run;


Proc SQl;
Create table want as
Select a.ID,a.Note,Price
FROM have1 a inner join have b on a.note=b.note
where a.id in ( Select ID from have1)
;QUIt;

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!

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
  • 741 views
  • 0 likes
  • 3 in conversation