data snl;
input
name $
hosts
firstdate
lastdate
;
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;
run;
^^^This is what I've gotten done. I'm unsure of how I'm suppose to implement the steps into the code.
As this is a homework assignment, please show us what you have tried. We'll be happy to help improve your code.
Hint: Read dates with a date-type informat. Then you can assign a format in Proc Print to display values as desired.
Sort requirement looks like it want to use the variable you called "hosts".
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
I can't seem put first and last name into one variable and change the dates into a specfic format.
This is what I have typed out and I'm unsure of which statements to use and where to put them. I'm unsure of what lenth I should set my variables at.
data snl;
input
name $ 3-5
hosts 13-14
firstdate
lastdate
;
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;
run;
No sorry I haven't. This class has been moving way too fast for me. I've never done programming before and it seems I must look through hours of notes to just find the right symbol.
Have you looked at the result of your data step? What values do you see for "name"? That is clue on how to modify the input to read the name.
Hint: what does the 3 - 5 after the Name mean? Look at the values and they will show you.
This exersize leads you to next subjects:
1) The INPUT statement - geting data into sas.
Search documentation google "sas documentation input statement".
2) Converting dates from display mode to sas dates and vice versa by using
INFORMAT and FORMAT statements by category - (on same page link as above).
Try to implement what you understood and test it.
Where did you copy this data from?
Once you get it working you should tell the instructor that displaying dates with only two digits for year should be anathema to programmers. Google Y2K problem.
The same for displaying date in either month,day,year or day,month,year order. Whichever of those two you pick will confuse half of your audience.
I merged your questions dealing with the same homework.
Given that you want to read fixed-width data, you have to use positional input and the proper informats.
Use @x (x being the position within a line, starting at 1) before the variable in question.
Use a $w. (w being the width) to read the name, so that the blank(s) in the names don't interfere.
Use MMDDYYw. and DATEw. informats for the dates.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.