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

So I have Data that's stacked like this:  

 

John 

890,,,900

red

Contractor

Marie

900,,,888 

purple

Manager

Giselle

100,,,000

orange

President 

Coming in as 4 different variables (name,id1,color, title) and I need to read them in with, I'm assuming, some combination of line holders and pointer controls. 

 

Currently I have 

 

data emp; 

     infile employee firstobs = 2 /* Because there is some random text in the file at the beginning*/ n = 3; 

    input #1 name 1-20 #2 id $10. #3 color $50. #4 title $50.; 

  right now, whenever I run this, it reads in the first line correctly and then skips a line and starts reading in everything which is causing everything else to mess up.  

 

So the output looks like this 

 

Name                             ID                         Color                   Title

 

John                            890,,,900                   Red                   Contractor 

900,,,888                     purple                        Manager           Giselle

 

Any idea why this is happening? I feel like i've tried an endless combination of line pointer controls and hold specifiers but haven't gotten anywhere 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It's not obvious what is wrong looking at your program.

 

Since you have 4 lines per block, it seems right to use n=4, not n=3.

 

Adding TRUNCOVER to the INFILE statement might help.

 

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

It's not obvious what is wrong looking at your program.

 

Since you have 4 lines per block, it seems right to use n=4, not n=3.

 

Adding TRUNCOVER to the INFILE statement might help.

 

 

ballardw
Super User

The problem is the way you provide the Informats on the input statement.

When you use

Input id $10. ; SAS reads 10 characters. If the value runs out then in continues on the next line. With list type data you may need the : input modifier to accept shorter values.

Similar, when you have Input name 1-20 your are reading a NUMERIC value.

You would want Input name $ 1-20.

 

Please. For text data to read paste it into a text box opened on the forum with the </> icon. The main message windows will reformat pasted text and sometimes inserts characters that you don't see. So we can't actually run against your data.

 

If your data is that simple an always is 4 lines you may be able to use the input statement / instruction to read from the next line as below.

data emp; 
    informat name $20. id $10. color $50. title $50.; 
    input name / id  / color  / title; 
datalines;
John 
890,,,900
red
Contractor
Marie
900,,,888 
purple
Manager
Giselle
100,,,000
orange
President 
;

Or

data emp; 
    input name $ 1-20 / id :$10. / color :$50. / title :$50.; 
datalines;
John 
890,,,900
red
Contractor
Marie
900,,,888 
purple
Manager
Giselle
100,,,000
orange
President 
;

 

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