BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MadQuidd
Obsidian | Level 7

I am trying to format dates into sas. I tried to format the input statement to accurately read in the dates but the variable 'first' will not show in the output data. I understand how to format the proc print (i think). Please help i dont understand why it wont work. 

the code is listed below:

 

data SNL;
length host $ 18;
input Host $ & Appearances @28 First mmddyyyy10. @44 Fifth date9.;
format first fifth mmddyy8.;
datalines;
Ben Affleck 5 2/19/2000 18-May-13
Alec Baldwin 16 4/21/1990 10-Dec-94
Drew Barrymore 6 11/20/1982 03-Feb-07
Candice Bergen 5 11/8/1975 19-May-90
Chevy Chase 8 2/18/1978 06-Dec-86
Danny DeVito 6 5/15/1982 09-Jan-93
John Goodman 13 12/2/1989 07-May-94
Elliott Gould 6 1/10/1976 16-Feb-80
Tom Hanks 8 12/14/1985 08-Dec-90
Buck Henry 10 1/17/1976 19-Nov-77
Steve Martin 15 10/23/1976 22-Apr-78
Bill Murray 5 3/7/1981 20-Feb-99
Justin Timberlake 5 10/11/2003 09-Mar-13
Christopher Walken 7 1/20/1990 19-May-01
;
run;
proc print data=snl;
format first ddmmyy8.;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11
data SNL;
length host $ 18;
input Host & $ Appearances First: mmddyy10. Fifth: date8.;
datalines;
Ben Affleck  5 2/19/2000 18-May-13
Alec Baldwin  16 4/21/1990 10-Dec-94
Drew Barrymore  6 11/20/1982 03-Feb-07
Candice Bergen  5 11/8/1975 19-May-90
Chevy Chase  8 2/18/1978 06-Dec-86
Danny DeVito  6 5/15/1982 09-Jan-93
John Goodman  13 12/2/1989 07-May-94
Elliott Gould  6 1/10/1976 16-Feb-80
Tom Hanks  8 12/14/1985 08-Dec-90
Buck Henry  10 1/17/1976 19-Nov-77
Steve Martin  15 10/23/1976 22-Apr-78
Bill Murray  5 3/7/1981 20-Feb-99
Justin Timberlake  5 10/11/2003 09-Mar-13
Christopher Walken  7 1/20/1990 19-May-01
;
run;
proc print data=snl;
format first ddmmyy8.;
run;

View solution in original post

2 REPLIES 2
mohamed_zaki
Barite | Level 11
data SNL;
length host $ 18;
input Host & $ Appearances First: mmddyy10. Fifth: date8.;
datalines;
Ben Affleck  5 2/19/2000 18-May-13
Alec Baldwin  16 4/21/1990 10-Dec-94
Drew Barrymore  6 11/20/1982 03-Feb-07
Candice Bergen  5 11/8/1975 19-May-90
Chevy Chase  8 2/18/1978 06-Dec-86
Danny DeVito  6 5/15/1982 09-Jan-93
John Goodman  13 12/2/1989 07-May-94
Elliott Gould  6 1/10/1976 16-Feb-80
Tom Hanks  8 12/14/1985 08-Dec-90
Buck Henry  10 1/17/1976 19-Nov-77
Steve Martin  15 10/23/1976 22-Apr-78
Bill Murray  5 3/7/1981 20-Feb-99
Justin Timberlake  5 10/11/2003 09-Mar-13
Christopher Walken  7 1/20/1990 19-May-01
;
run;
proc print data=snl;
format first ddmmyy8.;
run;
ballardw
Super User

Possibly too late for the "why" but for later readers.

 

This input statement:

input Host $ & Appearances @28 First mmddyyyy10. @44 Fifth date9.;

Says to always start reading the variable first in column 28.

It is important to note that if the data has tabs a tab character well generally be treated as a single character so you need to count actual character spaces used.

 

A simple by eye inspection of the posted data would tell us that the first date value appears in different positions.

In the first line of the example data I count 15 columns for the start of first. Even without running the program I expect to get a number of errors about invalid data.

Posting the log with messages would help diagnose specific issues.

 

The solution that @mohamed_zaki provided uses modified list input instead of fixed column to address that issue.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 798 views
  • 1 like
  • 3 in conversation