I have a date column in the format YYYYMM and I want to convert that to a number and not sas date number
Example: Date type 201708 should be converted to number 201708
Is there any way to do it?
Thanks
Is your current value actually numeric with a SAS format such as YYMMN6. or similar assigned?
Then in a data step
data want;
set have;
date = year(date)*100+month(date);
FORMAT date best6.;
run;
is one way. But I would strongly recommend not doing this as date values are ever so much more flexible than plain numeric values when dates are involved.
If your "date" is character then there are more gyrations as you cannot change the type of a variable
data want;
set have (rename=(date=datechar);
date = input(datechar, f6.);
drop datechar;
run;
But again I would suggest actually creating a SAS date value.
Otherwise we need a better example of your data and what you expect.
Try this:
data test;
length var_date 8;
length var_num 8;
format var_date yymmn6.;
var_date='01JUN2019'd;
var_num =input(put(var_date, yymmn6.), 6.);
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: