DATA Step, Macro, Functions and more

Reading raw file

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Reading raw file

hello all,

I want to read this raw data ,that i attached here, in sas.But there is a problem in my coding i can not find the right start point for each variable when using @ in the input statement, also the length of each variable is not clear for me.Bellow is my code. Any help is appreciated !


data tempy;
infile "C:\Users\FATEMEH\Desktop\summer2017work\temp.txt";
input @1 dept$5.    @7 wagecat$1.    @8 wagerate 7.2     @16manager$7.    @23 jobtype 3.;
proc print data=tempy;run;


Accepted Solutions
Solution
‎03-09-2018 03:42 PM
Super User
Posts: 13,886

Re: Reading raw file

It appears that your data is TAB delimited.

Try

data tempy;
   infile "C:\Users\FATEMEH\Desktop\summer2017work\temp.txt" dlm='09'x;
   informat  dept $5.  wagecat $1.   wagerate 7.2   manager $7.     jobtype 3.;
   input  dept    wagecat wagerate  manager  jobtype  ;
run;

I moved the informats to a separate line as they can cause issues when reading delimited text by forcing a read longer than the values that appear when the values have varying lengths such as your wagerate (5 to 7 ) and manager (4 to 7 characters).

 

View solution in original post


All Replies
Solution
‎03-09-2018 03:42 PM
Super User
Posts: 13,886

Re: Reading raw file

It appears that your data is TAB delimited.

Try

data tempy;
   infile "C:\Users\FATEMEH\Desktop\summer2017work\temp.txt" dlm='09'x;
   informat  dept $5.  wagecat $1.   wagerate 7.2   manager $7.     jobtype 3.;
   input  dept    wagecat wagerate  manager  jobtype  ;
run;

I moved the informats to a separate line as they can cause issues when reading delimited text by forcing a read longer than the values that appear when the values have varying lengths such as your wagerate (5 to 7 ) and manager (4 to 7 characters).

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 89 views
  • 1 like
  • 2 in conversation