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

Hi,

 

I have a dataset where the only variable is a long string delimited by "|"

 

An example of a record would be:

A||032345|99|||

 

I've tried some solutions that I've encountered online, but the problem is when you encounter the delimiters without anything between them. They just end up being ignored. Here's an example of code I've used.

 

data want (drop=i); set have;
  array parsed_vars $ new_var1-new_var%eval(&maxelements);
  do i = 1 to &maxelements;
  parsed_vars{i} = scan(orig_var,i,'.');
  end;
run;

I'd like the parsing output to appear as

  

orig_varnew_var1new_var2new_var3new_var4new_var5new_var6
A||032345|99|||A.03234599..

 

However, the output appears as:

 

orig_varnew_var1new_var2new_var3new_var4new_var5new_var6
A||032345|99|||A03234599...

 

I'm not sure how to fix it and would appreciate any help. If possible, I'd prefer to use proc sql if it can be done that way.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Do please RTM. Scan() has lots of options.

 

data test;
ori='A||032345|99|||';
array var(6) $10;
do i=1 to 6;
var(i)=scan(ori,i,'|','m');
end;
run;

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

Do please RTM. Scan() has lots of options.

 

data test;
ori='A||032345|99|||';
array var(6) $10;
do i=1 to 6;
var(i)=scan(ori,i,'|','m');
end;
run;
promo_at_work
Obsidian | Level 7
Perfect! Thank you so much!
ballardw
Super User

I would likely go back to the original file, probably use Proc Import with delimiter='|' getnames=No and guessingrows=max.

The default out of import will be to treat two delimiters to indicate a missing value. I believe the variable names would be var1-varn

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
  • 3 replies
  • 2895 views
  • 1 like
  • 3 in conversation