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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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