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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

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
  • 689 views
  • 0 likes
  • 3 in conversation