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.
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
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
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
NO. You can use it without change.
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
Assign ' ' as initial value of _d and _a
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.