BookmarkSubscribeRSS Feed
wfiona020
Calcite | Level 5

THIS IS WHAT I DID

Data d;
INPUT PERMNO INIT_DATA YYMMDD10. CUSIP $ END_DATA YYMMDD10.;
DATALINES;
10107 1999-11-01 59491810 2003-12-31
10145 1989-01-01 01951210 1999-12-02
10145 1999-12-03 43851610 2003-12-31
10401 1989-01-01 03017710 1994-04-21
10401 1994-04-22 00195710 2002-11-19
10401 2002-11-20 00195750 2003-12-31
10786 1989-01-01 08750910 1997-01-16
11308 1989-01-01 19121610 2003-12-31
;
RUN;

BUT THE DATA SHOWS IN BEST12 FORMAT.

WHY?

AND HOW DO I CHANGE IT INTO YYMMDD10.?

THANKS

2 REPLIES 2
Tom
Super User Tom
Super User

If you want the dates to print in a human recognizable way you need to attach a format specification to the variable.

You should also update your INPUT statement to either read the date value using LIST MODE like the other variables.

data d;
  input PERMNO INIT_DATA :YYMMDD10. CUSIP $ END_DATA :YYMMDD10.;
  format init_data end_data yymmdd10.;
datalines;
10107 1999-11-01 59491810 2003-12-31
10145 1989-01-01 01951210 1999-12-02
10145 1999-12-03 43851610 2003-12-31
10401 1989-01-01 03017710 1994-04-21
10401 1994-04-22 00195710 2002-11-19
10401 2002-11-20 00195750 2003-12-31
10786 1989-01-01 08750910 1997-01-16
11308 1989-01-01 19121610 2003-12-31
;

Or if you want to read them using FORMATTED mode then tell it exactly which column to start at to make sure it reads the the right 10 characters.  If you start reading at the space instead of the first digit of the year you will miss the last digit of the day of the month.

  input PERMNO @7 INIT_DATA YYMMDD10. CUSIP $ @27 END_DATA YYMMDD10.;

For example:

231  data d;
232    input PERMNO INIT_DATA YYMMDD10. CUSIP $ END_DATA YYMMDD10.;
233    format init_data end_data yymmdd10.;
234  datalines;

NOTE: Invalid data for END_DATA in line 235 25-34.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
235        10107 1999-11-01 594918   2003-12-31
PERMNO=10107 INIT_DATA=1999-11-01 CUSIP=594918 END_DATA=. _ERROR_=1 _N_=1
NOTE: The data set WORK.D has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
Kurt_Bremser
Super User

Use the colon modifier to prevent formatted input (which will ignore the delimiters), and assign display formats:

input permno init_data :yymmdd10. cusip $ end_data :yymmd10.;
format init_data end_data yymmdd10.;

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
  • 233 views
  • 0 likes
  • 3 in conversation