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
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.
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.