I import the data using proc import:
proc import
datafile='/data/bvd/AcademicsSample.txt'
out=bvd.ac
dbms=dlm
replace;
delimiter = '09'x;
run;
One of the extracted variables is Closing_date (proc contents result below):
# Variable Type Len Format Informat
4 Closing_date Num 8 BEST12. BEST32.
From proc print, I see the date as 20081231 for 31 December 2008.
Problem: I cannot extract the year from this date.
I tried using:
1) year=year(Closing_date); result is dots (log NOTE: Invalid argument to function YEAR(20081231) at line 324 column 7.)
2) year=year(datepart(Closing_date)); result is 1960 for all observations (no log NOTE)
3) substr(Closing_date,1,4); result is blanks (log NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 324:14)
4) I have tried a bunch of other options that I found online but nothing worked, although I might not have executed these options well
Please help!
This happens because SAS imports Closing_date as a plain number, not a SAS Date.
You can do this to convert to a SAS Date
data have;
date = 20081231;
newdate = input(put(date, 8.), yymmdd8.);
year = year(newdate);
format newdate date9.;
run;
This happens because SAS imports Closing_date as a plain number, not a SAS Date.
You can do this to convert to a SAS Date
data have;
date = 20081231;
newdate = input(put(date, 8.), yymmdd8.);
year = year(newdate);
format newdate date9.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.