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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3383 views
  • 1 like
  • 3 in conversation