06-18-2012 12:09 PM
If you really have these variables as character strings then SUBSTR(x,1,4) will take the first 4 characters of the field. If for some reason the value is pushed right in the field you could use the LEFT() or STRIP() function to remove the leading spaces first.
More likely you have the data stored as a number. If it is really a date in the format YYYYMMDD then you should store it as a date. Then the YEAR() function will be able to take the year part of the date for you.
If instead you just have it stored as number (For example 19,701,231) then you could use INT(datadate/10000) to find the digits from the 10 million to 10 thousands place. Or you could convert it to a date and then use the YEAR function. year(input(put(datadate,z8.),yymmdd8.))
03-09-2015 01:28 PM
This is exactly what I needed! Thanks!
For those using Miner, I have an account number 15 digits long (Char15). I only need the first 11.
SAS Code Node read:
data &EM_EXPORT_TRAIN; set &EM_IMPORT_DATA;
Returns the same value as Excel; =
06-18-2012 12:39 PM
If DATADATE is character, and left-hand-justified, here are a couple of simple tricks to getting the year.
If you want YEAR as numeric, read just the first four characters of DATADATE:
year = input(datadate, 4.);
If you want YEAR as character, copy into a shorter variable:
length year $ 4;
year = datadate;
If DATADATE is numeric, then other posters have mentioned the right issues. You have to begin with asking what number is actually stored there (the digits in your post, vs. a SAS date).