BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ashok3395
Fluorite | Level 6

Hi,

 

Kindly help me in converting YYYYMMDD (numeric) into date9. format or YYMMn6.

 

Example :

 

20181201-> which is in numeric format.

 

Regards,

Ashok Arunachalam

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11

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;

View solution in original post

8 REPLIES 8
r_behata
Barite | Level 11
data want;
input dt ;
format dt9 date9.;
dt9=input(put(dt,8.),yymmdd8.);

cards;
20181201
run;
Ashok3395
Fluorite | Level 6

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

 

r_behata
Barite | Level 11

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;
Ashok3395
Fluorite | Level 6

Thank you ...its working

Jagadishkatam
Amethyst | Level 16

Alternatively try the anydtdte. informat to read the dates.

 

data have;
input date: anydtdte.;
format date date9.;
cards;
20181201
;
Thanks,
Jag
Ashok3395
Fluorite | Level 6

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

 

 

Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
Ashok3395
Fluorite | Level 6
Thank you Jagadish.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 34953 views
  • 5 likes
  • 3 in conversation