BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sg_kr
Obsidian | Level 7

Hi ,

 

i have to read an unstructured data from a text file to SAS dataset 

 

raw data like below:

Description AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
assakndsklfdsfpsdskmcs'kfdskfnsd'vkmsdv;ls vlksnfdks'fjdsoifnsonvs;lnsohfsnskjfhso;fskfjslfks';fljslkfjs;lfjslkfj;lksfjslkfjos;kufoeisocnds;ojvnoriecnwiocns
fhdsiupfhwfnsdpcmdwpofwecmsd'lkvnpsfmspcns[oijsncspncdsvnsnccd
 
 
accountno  date current_balance credit debit total_bal
*********************************************************
1111 01/02/2000 100 20 40 80
 
2222 01/02/2000 10 20 30 0
2222 02/02/2000 40 10 2 48
 
 
accountno  date current_balance credit debit total_bal
*********************************************************
1111 01/02/2000 100 20 40 80
 
2222 01/02/2000 10 20 30 0
222202/02/20004010248
 
 
accountno  date current_balance credit debit total_bal
*********************************************************
1111 01/02/2000 100 20 40 80
 
2222 01/02/2000 10 20 30 0
222202/02/20004010248
 
accountno  date current_balance credit debit total_bal
*********************************************************
1111 01/02/2000 100 20 40 80
 
2222 01/02/2000 10 20 30 0
222202/02/20004010248
 
Output---
i want dataset to be with the following columns
accountno  date current_balance credit debit total_bal
 
kindly please help us on this
 
 
also i have attached the file as well
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
filename x 'c:\temp\test.txt' encoding='utf8' termstr=crlf;
data have;
infile x  dlm='09'x dsd;
input @;
if anydigit(_infile_) ne 1 then delete;
input (accountno  date current_balance credit debit total_bal) (: $40.);
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User
filename x 'c:\temp\test.txt' encoding='utf8' termstr=crlf;
data have;
infile x  dlm='09'x dsd;
input @;
if anydigit(_infile_) ne 1 then delete;
input (accountno  date current_balance credit debit total_bal) (: $40.);
run;
sg_kr
Obsidian | Level 7
thanks for the response, just want to know about the two input statements in the data step.

and how to deal if my columns names are two words like account no, instead of accountno
Ksharp
Super User
/*OK. Using liternal name syntax.*/

option validvarname=any;  *Make sure variable name could contain blanks;
filename x 'c:\temp\test.txt' encoding='utf8' termstr=crlf;
data have;
infile x  dlm='09'x dsd;
input @;
if anydigit(_infile_) ne 1 then delete;
input ('account no'n  date current_balance credit debit total_bal) (: $40.);
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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