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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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