Logic help required

Reply
Contributor
Posts: 60

Logic help required

Hi,

I have two datasets.

dataset1:    

QMStateValue
AAL25
BAZ 85
CDC35
DKS95

dataset2:

StateQMFrom_valueTo_ValuePoints
ALA05010
ALA5110020
AZB0501
AZB511002
DCC05010
DCC5110020
KSA0501
KSA511002

I have to merge these two datasets in a way that if 'Value' variable in dataset1 fall in the range of 'From_value' and 'To_value' variable in dataset2 then corresponding 'From_Value', 'To_Value', & 'Points' should be merged with dataset 1.

output should be like :

QMStateValueFrom_ValueTo_ValuePoints
AAL2505010
BAZ85511002
CDC3505010
DKS9551100. (missing value)

I don`t know how to merge it this way.

Your help is much appreciated.

Thanks,

Saravanan

Super User
Super User
Posts: 7,074

Re: Logic help required

Posted in reply to Saravanan

Use PROC SQL.

proc sql ;

  create table want as select *

    from dataset1 a left join dataset2 b

    on a.state=b.state

    and a.value between b.from_value and b.to_value

  ;

quit;

Contributor
Posts: 60

Re: Logic help required

Thanks a lot Tom.

I just made a small correction to your query to make it work.

I added the condition a.QM=b.Qm as well.

Much appreciated.

Ask a Question
Discussion stats
  • 2 replies
  • 177 views
  • 0 likes
  • 2 in conversation