Help using Base SAS procedures

How to Read input File

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

How to Read input File

Hi All,

I am new to SAS and these days learning Base SAS Programming, I am not able to read this input file.

File name- Test.txt

data in file are Name, Age and Gender

like this.....

Dharmendra Kumar Yadav 22 M

Sonu 34 M

Deepa 45 F

David Fills 44 M

John Don 33 M

Can any one tell me how to read this data with these vars- Name, Age and Gender.

Thanks!! in advance


Accepted Solutions
Solution
‎12-07-2014 08:51 AM
Respected Advisor
Posts: 3,777

Re: How to Read input File

You know that age is the second word from the right and you can use that to find the length of name.

data names;
   input @;
   call scan(_infile_,-2,p,l,' ');
   l = p-1;
  
input name $varying64. l age sex :$1.;
  
drop p l;
   cards;
Dharmendra Kumar Yadav 22 M
Sonu 34 M
Deepa 45 F
David Fills 44 M
John Don 33 M
;;;;
   run;
proc print;
  
run;

12-7-2014 7-48-42 AM.png

View solution in original post


All Replies
Solution
‎12-07-2014 08:51 AM
Respected Advisor
Posts: 3,777

Re: How to Read input File

You know that age is the second word from the right and you can use that to find the length of name.

data names;
   input @;
   call scan(_infile_,-2,p,l,' ');
   l = p-1;
  
input name $varying64. l age sex :$1.;
  
drop p l;
   cards;
Dharmendra Kumar Yadav 22 M
Sonu 34 M
Deepa 45 F
David Fills 44 M
John Don 33 M
;;;;
   run;
proc print;
  
run;

12-7-2014 7-48-42 AM.png
Contributor
Posts: 37

Re: How to Read input File

Thanks!! a ton.

It helped.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 244 views
  • 1 like
  • 2 in conversation