- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Kindly help me in converting YYYYMMDD (numeric) into date9. format or YYMMn6.
Example :
20181201-> which is in numeric format.
Regards,
Ashok Arunachalam
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
input dt ;
format dt9 date9.;
dt9=input(put(dt,8.),yymmdd8.);
cards;
20181201
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you ...its working
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Alternatively try the anydtdte. informat to read the dates.
data have;
input date: anydtdte.;
format date date9.;
cards;
20181201
;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content