How to search for data from one column in another column in SAS using Proc-SQL?

Asked

Viewed 103 times

1

I need to perform a query in which I have to do a Join between two Tables. The column I should use to do the "On" of Join is the CPF/CNPJ. However, table A’s CNPJ data is only with 12 numbers, while in table B, it is complete, with 14.

I thought I’d do something like "contain" using %, but I can’t use column indicative, just text.

PROC SQL;
CREATE TABLE TESR.CAPTACAO_TOTAL AS
SELECT 
A.*,
B.ID_CLI_PRINC,
B.NOM_CLI,
B.NOM_SUB_SGMTO_CLI
FROM
WORK.ESTOQUE_CAPTACAO_TOTAL AS A
LEFT JOIN
MISXRM.LASR_NEW AS B
ON A.CPF_CLIENTE = B.NUM_CPF_CNPJ_CLI;
QUIT;

I thought I’d do something like "contain" using %, but it doesn’t work because I can’t use column indicative, only text.

PROC SQL;
CREATE TABLE TESR.CAPTACAO_TOTAL AS
SELECT 
A.*,
B.ID_CLI_PRINC,
B.NOM_CLI,
B.NOM_SUB_SGMTO_CLI
FROM
WORK.ESTOQUE_CAPTACAO_TOTAL AS A
LEFT JOIN
MISXRM.LASR_NEW AS B
ON %A.CPF_CLIENTE% = B.NUM_CPF_CNPJ_CLI;
QUIT;

  • Welcome to Stack Overflow, pal! Ideally, you should provide a minimum reproducible example: https://answall.com/help/minimal-reproducible-example . Without this, any help that we try to give will be a kick, because we do not know the type of the variable (if it is string, if it is numerical), which are the digits that are missing, if the CNPJ has dots, bars, dashes, in short. Ideally you provide an example, even if fictitious of what data you have, and the result you expect.

1 answer

1

If the missing digits are the 2 on the right, try using the Left function to get only the 12 digits on the left:

ON A.CPF_CLIENTE = LEFT(B.NUM_CPF_CNPJ_CLI, 12)

I hope it helps

Browser other questions tagged

You are not signed in. Login or sign up in order to post.