BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tianerhu
Pyrite | Level 9
data work.homework;
infile datalines dsd;
input    name  $  
         age 
         height;

datalines;
John McCloskey 35 71
June Rosesette 10 43
TinekeJones 9 37
;
proc print data = work.homework;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The main thing is you need to fix the data so that it can be parsed.

 

Either use a delimiter other than space between the values on the lines.  Your current code is expecting a comma as the delimiter as that is the default when the DSD option is used.

data homework;
  infile datalines dsd;
  input name :$30. age height;
datalines;
John McCloskey,35,71
June Rosesette,10,43
TinekeJones,9,37
;

Or insure there are at least two spaces after the name (and no more than one space in a row in the name) so you can use the & modifier.

data homework;
  input name &:$30. age height;
datalines;
John McCloskey  35 71
June Rosesette  10 43
TinekeJones      9 37
;

 

View solution in original post

5 REPLIES 5
tianerhu
Pyrite | Level 9

this program above does not work. Please give me a help.

PaigeMiller
Diamond | Level 26

If you have two spaces after the name, and you use the & to read in the names, then everything will work.

https://www.geeksforgeeks.org/sas-how-to-read-character-using-ampersand/

--
Paige Miller
tianerhu
Pyrite | Level 9
Thank you for your help.
Tom
Super User Tom
Super User

The main thing is you need to fix the data so that it can be parsed.

 

Either use a delimiter other than space between the values on the lines.  Your current code is expecting a comma as the delimiter as that is the default when the DSD option is used.

data homework;
  infile datalines dsd;
  input name :$30. age height;
datalines;
John McCloskey,35,71
June Rosesette,10,43
TinekeJones,9,37
;

Or insure there are at least two spaces after the name (and no more than one space in a row in the name) so you can use the & modifier.

data homework;
  input name &:$30. age height;
datalines;
John McCloskey  35 71
June Rosesette  10 43
TinekeJones      9 37
;

 

tianerhu
Pyrite | Level 9
Thanks a lot.

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
  • 5 replies
  • 631 views
  • 0 likes
  • 3 in conversation