BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Elenatec
Calcite | Level 5

Hi,

I am new to SAS very much appreciated from your reply. My client gave me a txt file which look like the file I have attached, I would like to know how use SAS to capture valid data or skip unessary rows from the raw files and replace those empty column such as date and area.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK.

filename x  'c:\temp\query1.txt';
data x;
 infile x  expandtabs  pad ;
 input @;
 if left(_infile_) in: ('FIles' 'Date' '======') or missing(_infile_) then delete;
  else  input date $ 8-16 area $ 22-28 id $ 31-39 type $ 40-44 country $ 47-65;
run;
data want;
 set x;
 retain _d _a '            ';
 if not missing(date) then _d=date;
 if not missing(area) then _a=area;
 date=coalescec(date,_d);
 area=coalescec(area,_a);
 drop _d _a;
run;

Ksharp

View solution in original post

5 REPLIES 5
Ksharp
Super User

OK.

filename x  'c:\temp\query1.txt';
data x;
 infile x  expandtabs  pad ;
 input @;
 if left(_infile_) in: ('FIles' 'Date' '======') or missing(_infile_) then delete;
  else  input date $ 8-16 area $ 22-28 id $ 31-39 type $ 40-44 country $ 47-65;
run;
data want;
 set x;
 retain _d _a '            ';
 if not missing(date) then _d=date;
 if not missing(area) then _a=area;
 date=coalescec(date,_d);
 area=coalescec(area,_a);
 drop _d _a;
run;

Ksharp

Elenatec
Calcite | Level 5

Hi Ksharp,

Thanks for your quick reply, I will try and learn your code atm.So late on I recieved another txt file from the client again now all the "tab" changed to "space" does the expandtabs effected with your code?

Ong

Ksharp
Super User

NO. You can use it without change.

Elenatec
Calcite | Level 5

Hi Ksharp,

Many Thanks, I am totally new to this SAS even I have basic programming languages knowledge still can't complete my work, very much appreciated from your help. one last questiong about the code 

retain _d _a '            ';

whats the purpose of the last '              ' section?

Ong

Ksharp
Super User

Assign '       '    as initial value of _d and _a

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1842 views
  • 6 likes
  • 2 in conversation