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

Suppose I have a dataset like this. The date is in character format. I need to convert it into date format and choose only current month data from the below dataset. It should be dynamic. Also I need another dataset where I need previous month data only. This also needs dynamic. I could have chosen month(transmonth)= current month but I need year also. Please help

 

data one ;
input obs id jobcat $ transmonth $11. ;
datalines;
1 1254 one 29AUG2019
2 9936 two 19AUG2019
3 7529 two 01AUG2019
4 9154 one 03AUG2019
5 7741 two 18JUL2019
6 8896 two 11JUL2019

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data one ;
infile datalines truncover;
input obs id jobcat :$ transmonth :$11. wage :$10. rating;
datalines;
1 1254 one 29AUG2019 $11000.00 2
2 9936 two 19AUG2019 $5,000.00 0
3 7529 two 01AUG2019 $9,000.00 1
4 9154 one 03AUG2019 $10000.00 2
5 7741 two 18JUL2019 $9,500.00 3
6 8896 two 11JUL2019 $9,600.00 4
;
run;

data want;
set one;
numeric_date=input(transmonth,date9.);
if put(today(),monyy7.)=put(numeric_date,monyy7.);
format numeric_date date9.;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data one ;
infile datalines truncover;
input obs id jobcat :$ transmonth :$11. wage :$10. rating;
datalines;
1 1254 one 29AUG2019 $11000.00 2
2 9936 two 19AUG2019 $5,000.00 0
3 7529 two 01AUG2019 $9,000.00 1
4 9154 one 03AUG2019 $10000.00 2
5 7741 two 18JUL2019 $9,500.00 3
6 8896 two 11JUL2019 $9,600.00 4
;
run;

data want;
set one;
numeric_date=input(transmonth,date9.);
if put(today(),monyy7.)=put(numeric_date,monyy7.);
format numeric_date date9.;
run;
novinosrin
Tourmaline | Level 20

Hello @sameer112217  This completes your question

 

data current_monthyear prevmonth_curr_year;
set one;
numeric_date=input(transmonth,date9.);
if put(today(),monyy7.)=put(numeric_date,monyy7.) then output current_monthyear;
else if put(intnx('mon',today(),-1),monyy7.)=put(numeric_date,monyy7.) then output prevmonth_curr_year;
format numeric_date date9.;
run;
sameer112217
Quartz | Level 8

thanks