Hi everyone,
could you kinldy help to convert Char(13) to date. The data char(13) is '2019-12-31 00' and I want to convert it do date. Another thing is that I want to select all information from one table and indicate that I only want 31 Dec 2019. This convertion i will use in the qery bellow.
proc sql;
create table teste_dmk as select dt_referencia,
gbncli as c_ndc,
gbncli_activo as c_ind_activo
from trs_mkt.trs_gbcli_activo_inactivo
where dt_referencia=31122019; HERE I NEED HELP.
quit;
you can try below code
proc sql;
create table teste_dmk as select input(scan(dt_referencia,1,' '),yymmdd10.) as dt_referencia2,
gbncli as c_ndc,
gbncli_activo as c_ind_activo
from trs_mkt.trs_gbcli_activo_inactivo
having dt_referencia2='31dec2019'd;
quit;
Hi @Romeo1
For the conversion into date, you can use the input() function with the proper informat:
data have;
format want date9.;
have = '2019-12-31 00';
want = input(substr(have,1,10), YYMMDD10.);
run;
For the query, you can specify "31DEC2019"d
proc sql;
create table teste_dmk as select dt_referencia,
gbncli as c_ndc,
gbncli_activo as c_ind_activo
from trs_mkt.trs_gbcli_activo_inactivo
where dt_referencia="31DEC2019"d;
quit;
you can try below code
proc sql;
create table teste_dmk as select input(scan(dt_referencia,1,' '),yymmdd10.) as dt_referencia2,
gbncli as c_ndc,
gbncli_activo as c_ind_activo
from trs_mkt.trs_gbcli_activo_inactivo
having dt_referencia2='31dec2019'd;
quit;
What is actually in the data?
First are you sure it is character and not a date (or datetime) value that is just being displayed using that year month day ordered string?
Why are you using the SCAN function? If you specify a width in the informat specification then only the first 10 characters will be used.
INPUT(DT_REFERENCIA,yymmdd10.)='31dec2019'd
And perhaps most important if you just want to the one value then why convert it to an actual date at all?
DT_REFERENCIA like '2019-12-31%'
Is the libref TRS_MKT pointing at some external database system? Perhaps SAS is unable to convert your code to run in the database and is pulling the whole database across ot SAS and then summarizing. Try writing an explicit passthru query. Note that means you need to use the remote database's version of SQL.
PROC SQL;
connect using TRS_MKT;
select * from connection to TRS_MKT
(SELECT CLNCLI AS C_NDC, COUNT(*) AS NR_REGISTOS
FROM TRS_GBCLI_ACTIVO_INACTIVO
where DT_REFERENCIA like '2019-12-31%'
group by CLNCLI
)
ORDER BY 2 DESC
;
QUIT;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.