BookmarkSubscribeRSS Feed
sonyk
Calcite | Level 5
I have a text file test.txt like this :

This is class room 1

ID STUDENTNAME AGE WEIGHT(pounds)

1 Robert 13 70
2 Mary 12 75
3 Nicole 11 79

This is class room 2

ID STUDENTNAME AGE WEIGHT(pounds)

4 charles 15 80
5 Kathy 14 85
6 Jen 10 70

The above is test.txt file.I have to import it as data set given below:

ID STUDENTNAME AGE WEIGHT(pounds)

1 Robert 13 70
2 Mary 12 75
3 Nicole 11 79
4 charles 15 80
5 Kathy 14 85
6 Jen 10 70
2 REPLIES 2
art297
Opal | Level 21
There a probably a number of ways. One might be something like:
[pre]
data need;
infile "c:\test.txt";
length id $3;
length studentname $10;
input;
if _infile_ ne "" then do;
if anydigit(substr(_infile_,1,1)) then do;
id=scan(_infile_,1);
studentname=scan(_infile_,2);
age=input(scan(_infile_,3),best12.);
weight_pounds=input(scan(_infile_,4),best12.);
output;
end;
end;
run;
[/pre]
Art
> I have a text file test.txt like this :
>
> This is class room 1
>
> ID STUDENTNAME AGE WEIGHT(pounds)
> 1 Robert 13 70
> 2 Mary 12 75
> 3 Nicole 11 79
> This is class room 2
>
> ID STUDENTNAME AGE WEIGHT(pounds)
> 4 charles 15 80
> 5 Kathy 14 85
> 6 Jen 10 70
> e above is test.txt file.I have to import it as data
> set given below:
>
> ID STUDENTNAME AGE WEIGHT(pounds)
> 1 Robert 13 70
> 2 Mary 12 75
> 3 Nicole 11 79
> 4 charles 15 80
> 5 Kathy 14 85
> 6 Jen 10 70
Ksharp
Super User
[pre]
data need(drop=row);
infile "c:\temp\test.txt" length=len;
input row $varying200. len;
if not missing(input(scan(row,1),?? best10.)) then do;
id=scan(row,1);studentname=scan(row,2);age=scan(row,3);weight=scan(row,4);
output;
end;
run;
[/pre]


Ksharp

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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