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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 895 views
  • 0 likes
  • 3 in conversation