BookmarkSubscribeRSS Feed
Godzilla_Hat
Obsidian | Level 7

This what I'm supposed to do to the codeThis what I'm supposed to do to the code

 

This is the datasetThis is the dataset

 

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.

10 REPLIES 10
PaigeMiller
Diamond | Level 26

As this is a homework assignment, please show us what you have tried. We'll be happy to help improve your code.

--
Paige Miller
ballardw
Super User

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.

Godzilla_Hat
Obsidian | Level 7

I can't seem put first and last name into one variable and change the dates into a specfic format. 

Part 1 .png

 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;
Reeza
Super User
Did you learn the INPUT statement? Specifically the & or && symbols? The use of double spaces?
Since you're creating the datalines you could also add delimiters besides just spaces? That's usually the easiest method.
Godzilla_Hat
Obsidian | Level 7

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. 

ballardw
Super User

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.

Shmuel
Garnet | Level 18

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.

     

tarheel13
Rhodochrosite | Level 12

Where did you copy this data from? 

Tom
Super User Tom
Super User

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.  

Kurt_Bremser
Super User

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.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 10 replies
  • 1217 views
  • 1 like
  • 8 in conversation