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