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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

8 REPLIES 8
mnjtrana
Pyrite | Level 9

You can try missing function:

 

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

run;


Cheers from India!

Manjeet
may0423
Obsidian | Level 7

thank you for the quick response!

 

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

Reeza
Super User

Post your code and log please

may0423
Obsidian | Level 7

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;

Ksharp
Super User

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;
may0423
Obsidian | Level 7

I just adapted 

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

a little bit. It worked! thank you 

Reeza
Super User

@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. 

Ksharp
Super User
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 3515 views
  • 3 likes
  • 4 in conversation