BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kateb409
Obsidian | Level 7

Hi there!

I am working in SAS On Demand version 9.4_m6 on Linux X64 operating system. 

I need help reading in some delimited in-stream data into SAS. This is the question on my homework and the provided in-stream data:

I am running into the issue of capturing the full length of the state name 'Washington' in my results. I have tried using the dsd, missover, and truncover options and it did not help. This is the code I used: 

 

data states;
infile datalines;
input state :$10.
         population :comma10. ;
datalines;
   Washington 7,170,351
   Ohio 11,613,423
   Florida 21,299,325
;

proc print data = states;
run;

 

And this is the result I get: the 'n' is cut off from 'Washington'

 

 

 Please let me know if anyone has had this issue and knows how to fix it. Thanks!

-Kate

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The key thing here is something I can tell from your photographs that you don't actually mention in your problem description.  You are using SAS/Studio to edit and submit the code.

 

There is nothing seriously wrong with the syntax of your data step (you don't need to the INFILE statement, you don't want to have leading spaces on your lines of data). So the issue is the content of your datalines.  When you have lines of code with TAB characters in them using SAS Display Manager the tabs are not submitted as part of the program.  But when you use SAS/Studio they are kept in the datalines and so will cause issues, especially when trying to read numeric values.

 

There are a number of ways to fix this.  The best is to make sure not to include actual tabs in your programs. There are settings in the SAS editors to insert spaces when when you hit the tab key on your keyboard.

 

You could also use the EXPANDTABS option on an INFILE statement.

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Hi , Can you try expanding the width of the informat from 10 to something like 12?

 

input state :$12.

kateb409
Obsidian | Level 7

Hi there,

I actually did try using :$11 and that works, however, it does not make sense to me because the word 'Washington' only has 10 characters in it. I was wondering if there was another reason this syntax was not working for me.

-Kate

jimbarbour
Meteorite | Level 14

That's odd.  The code works perfectly fine for me.  I'm on Windows, so maybe there's some difference there.

 

Try left justifying your data lines.

jimbarbour_0-1600828320170.png

Data lines should always be hard up to the left margin.  It shouldn't matter with a : modifier with a $10 informat, but let's try it.  If that doesn't work, change your definition to $11.  Again, it shouldn't matter, but if it's lopping off a character, let's give it more room.

 

Jim

Tom
Super User Tom
Super User

The key thing here is something I can tell from your photographs that you don't actually mention in your problem description.  You are using SAS/Studio to edit and submit the code.

 

There is nothing seriously wrong with the syntax of your data step (you don't need to the INFILE statement, you don't want to have leading spaces on your lines of data). So the issue is the content of your datalines.  When you have lines of code with TAB characters in them using SAS Display Manager the tabs are not submitted as part of the program.  But when you use SAS/Studio they are kept in the datalines and so will cause issues, especially when trying to read numeric values.

 

There are a number of ways to fix this.  The best is to make sure not to include actual tabs in your programs. There are settings in the SAS editors to insert spaces when when you hit the tab key on your keyboard.

 

You could also use the EXPANDTABS option on an INFILE statement.

 

kateb409
Obsidian | Level 7

Hey Tom,

 

Thanks so much for this! Both options worked. I knew it would end up being something extremely simple.

 

I apologize for not mentioning that I am using SAS Studio to edit and submit data. I will keep that in mind for next time. 

 

-Kate

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
  • 1079 views
  • 4 likes
  • 4 in conversation