Hi,
Kindly help me in converting YYYYMMDD (numeric) into date9. format or YYMMn6.
Example :
20181201-> which is in numeric format.
Regards,
Ashok Arunachalam
Apparently you are querying on the column which is having the sas date value internally , with a formatted values of year and month. Check this modified query.
%let runasofdate = 20181001;
options mprint mlogic symbolgen;
%put &runasofdate.;
data PARTY_PROF;
input tran_month yymmn6.;
format tran_month yymmn6.;
cards;
201810
201811
201710
run;
data x;
dt = symget ('runasofdate');
rndt = cats("'",dt,"'");
call symput ('rndt',rndt);
mnth = substr(dt,1,6);
call symput('m_key',strip(mnth));
run;
%put &m_key.;
data _test;
set PARTY_PROF;
where put(tran_month,yymmn6.)="&m_key.";
run;
data want;
input dt ;
format dt9 date9.;
dt9=input(put(dt,8.),yymmdd8.);
cards;
20181201
run;
Hi,
Thanks for the update!!!
below is my scenario,
I'm having the table Trans_month(column) which is in date format (yymmn6.)--> ex :201810.
And im trying to run the below code/logic to extract the data.
%let runasofdate = 20181001;
options mprint mlogic symbolgen;
%put &runasofdate.;
data x;
dt = symget ('runasofdate');
rndt = cats("'",dt,"'");
call symput ('rndt',rndt);
mnth = substr(dt,1,6);
call symput('m_key',strip(mnth));
run;
data _test;
set PARTY_PROF;
where tran_month=&m_key.;
run;
while running the above code im getting nil records ,even though im having the data in the main table.
Regards,
Ashok Arunachalam
Apparently you are querying on the column which is having the sas date value internally , with a formatted values of year and month. Check this modified query.
%let runasofdate = 20181001;
options mprint mlogic symbolgen;
%put &runasofdate.;
data PARTY_PROF;
input tran_month yymmn6.;
format tran_month yymmn6.;
cards;
201810
201811
201710
run;
data x;
dt = symget ('runasofdate');
rndt = cats("'",dt,"'");
call symput ('rndt',rndt);
mnth = substr(dt,1,6);
call symput('m_key',strip(mnth));
run;
%put &m_key.;
data _test;
set PARTY_PROF;
where put(tran_month,yymmn6.)="&m_key.";
run;
Thank you ...its working
Alternatively try the anydtdte. informat to read the dates.
data have;
input date: anydtdte.;
format date date9.;
cards;
20181201
;
Hi Jag,
Thanks for the update!!!
below is my scenario,
I'm having the table Trans_month(column) which is in date format (yymmn6.)--> ex :201810.
And im trying to run the below code/logic to extract the data.
%let runasofdate = 20181001;
options mprint mlogic symbolgen;
%put &runasofdate.;
data x;
dt = symget ('runasofdate');
rndt = cats("'",dt,"'");
call symput ('rndt',rndt);
mnth = substr(dt,1,6);
call symput('m_key',strip(mnth));
run;
data _test;
set PARTY_PROF;
where tran_month=&m_key.;
run;
while running the above code im getting nil records ,even though im having the data in the main table.
Regards,
Ashok Arunachalam
we could simplify the program as below by using the %substr instead of call symput and a data step
%let m_key = %substr(20181001,1,6);
%put &m_key.;
options nomprint nomlogic nosymbolgen;
data _test;
set PARTY_PROF;
where date=&m_key.;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.