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 connect 2 tables but I do not know how to do it because of the date in text of the second table $ 6 ..
Can you help me.

 

Table 1   Table 2 
      
COMAXCOOPUDAOPU COMAXComois
37351OPUCTC00046D2CW02-juil-19 37351201907
42235OPUCTC0004TOCFP05-nov-19 42235201911
42235OPUCTC0004UJ9RI26-déc-19 42243202001
42243OPUCTC0004XHLP610-janv-20 42251201911
42251OPUCTC0004UJD3G19-nov-19 42265201912
42265OPUCTC0004U8XL620-déc-19 42268201911
42268OPUCTC0004TOJYV26-nov-19 103891201909
103891OPUCTC0004OCEP115-sept-19   
42265OPUCTC0004U8XL620-janv-19   
      
      
      

 

 

 

Want  
   
COMAXComoisCOOPU
37351201907OPUCTC00046D2CW
42235201911OPUCTC0004TOCFP
42243202001OPUCTC0004XHLP6
42251201911OPUCTC0004UJD3G
42265201912OPUCTC0004U8XL6
42268201911OPUCTC0004TOJYV
103891201909OPUCTC0004OCEP1
   
   

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Create a comois variable in the first table, and join on that:

data table1;
input comax :$5. coopu :$20. daopu :yymmdd10.;
comois = put(daopu,yymmn6.);
datalines;
37351 OPUCTC00046D2CW 2019-07-02
42235 OPUCTC0004TOCFP 2019-11-05
42235 OPUCTC0004UJ9RI 2019-12-26
;

data table2;
input comax :$5. comois :$6.;
datalines;
37351 201907
42235 201911
;

proc sql;
create table want as
select t1.comax, t2.comois, t1.coopu
from table1 t1, table2 t2
where t1.comax = t2.comax and t1.comois = t2.comois;
quit;

Please supply example data in usable form (see the above for reference), so we know exactly what you're talking about.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Create a comois variable in the first table, and join on that:

data table1;
input comax :$5. coopu :$20. daopu :yymmdd10.;
comois = put(daopu,yymmn6.);
datalines;
37351 OPUCTC00046D2CW 2019-07-02
42235 OPUCTC0004TOCFP 2019-11-05
42235 OPUCTC0004UJ9RI 2019-12-26
;

data table2;
input comax :$5. comois :$6.;
datalines;
37351 201907
42235 201911
;

proc sql;
create table want as
select t1.comax, t2.comois, t1.coopu
from table1 t1, table2 t2
where t1.comax = t2.comax and t1.comois = t2.comois;
quit;

Please supply example data in usable form (see the above for reference), so we know exactly what you're talking about.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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