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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
Satori
Quartz | Level 8
Thanks!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 883 views
  • 1 like
  • 2 in conversation