Help using Base SAS procedures

How to skip rows with retain statment?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

How to skip rows with retain statment?

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.

Attachment

Accepted Solutions
Solution
‎05-06-2013 08:44 AM
Super User
Posts: 9,676

Re: How to skip rows with retain statment?

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


All Replies
Solution
‎05-06-2013 08:44 AM
Super User
Posts: 9,676

Re: How to skip rows with retain statment?

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

Occasional Contributor
Posts: 17

Re: How to skip rows with retain statment?

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

Super User
Posts: 9,676

Re: How to skip rows with retain statment?

NO. You can use it without change.

Occasional Contributor
Posts: 17

Re: How to skip rows with retain statment?

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

Super User
Posts: 9,676

Re: How to skip rows with retain statment?

Assign '       '    as initial value of _d and _a

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 277 views
  • 6 likes
  • 2 in conversation