DATA Step, Macro, Functions and more

Fill in Blanks with 'NA'

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Fill in Blanks with 'NA'

Hello~

 

I am trying to replace blanks (which were not noted as '.', see attachment, line5, line8-9, line13-14) with 'NA' by if location =' ' then 'NA'; but nothing happened. Please help. Thank you!

 

 


20161226220050.jpg

Accepted Solutions
Solution
‎12-26-2016 11:37 PM
Super User
Posts: 10,046

Re: Fill in Blanks with 'NA'

There are some unprintable character other than white blank.

 

data x;
location='      ';output;
location='09'x;output;
location='xxxxxx';output;
run;
data x;
 set x;
 if prxmatch('/^\s+$/',location) then new='NA        ';
  else new=location;
run;

View solution in original post


All Replies
Contributor
Posts: 52

Re: Fill in Blanks with 'NA'

You can try missing function:

 

IF Missing(Location) then Location = 'NA';

run;


Cheers from India!

Manjeet
Contributor
Posts: 24

Re: Fill in Blanks with 'NA'

thank you for the quick response!

 

but it doesn't work......T.T

Super User
Posts: 19,876

Re: Fill in Blanks with 'NA'

Post your code and log please

Contributor
Posts: 24

Re: Fill in Blanks with 'NA'

Besides, how could I extract the location between  <dt>Location</dt> <dd> and </dd>? (see attachment)

 

data testlocation;
filename indata url 'http://forums.vwvortex.com/showthread.php?7286873-To-our-readers' lrecl=10000;
infile indata length=len;
input record $varying10000. len;
input @ '<dt>Join Date</dt> <dd>' / location :&$10000. ;
if location = ' ’ then location = ‘NA’;

data order_location;
set work. testlocation;
rank_num=_n_;
run;

Solution
‎12-26-2016 11:37 PM
Super User
Posts: 10,046

Re: Fill in Blanks with 'NA'

There are some unprintable character other than white blank.

 

data x;
location='      ';output;
location='09'x;output;
location='xxxxxx';output;
run;
data x;
 set x;
 if prxmatch('/^\s+$/',location) then new='NA        ';
  else new=location;
run;
Contributor
Posts: 24

Re: Fill in Blanks with 'NA'

I just adapted 

 if prxmatch('/^\s+$/',location) then new='NA        ';
  else new=location;

a little bit. It worked! thank you 

Super User
Posts: 19,876

Re: Fill in Blanks with 'NA'


may0423 wrote:

see attachment

 

A picture attachment is not helpful. If we want to mock up code we have to manually type out your data.  If you have blank characters besides spaces there's no way to check. 

 

Post as text or a SAS dataset but posting an image is not very useful. 

Super User
Posts: 10,046

Re: Fill in Blanks with 'NA'

filename indata url 'http://forums.vwvortex.com/showthread.php?7286873-To-our-readers' lrecl=10000;

data testlocation;
infile indata length=len;
input record $varying10000. len;
retain start;
if record =: '<body>' then start=1;
if start then do;
 record=prxchange('s/\<[^\<\>]+\>//',-1,record);
 if not prxmatch('/^\s+$/',record) then output;
end;
run;


data want;
 set testlocation;
 lag=lag(record);
 if prxmatch('/^\s*View Profile/',record) then do;record=lag;output;end;
 if prxmatch('/^\s*(Join Date|Location|Posts)/',record) then output;
run;
☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 273 views
  • 2 likes
  • 4 in conversation