DATA Step, Macro, Functions and more

Reading raw data separated by semicolons

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Reading raw data separated by semicolons

I have raw data consisting of a long string of numbers separated by semicolons. Like this:

1; 2; 3; 4; 5; …

I don’t know the number of values in advance.

I’d like to read these in using a data step and create one observation per value.

I’ve looked at several examples of using the input statement, but nothing works the way I would like it to.

Anyone have a suggestion?


Accepted Solutions
Solution
‎06-23-2016 06:53 PM
Respected Advisor
Posts: 3,799

Re: Reading raw data separated by semicolons

Posted in reply to TedShelly

You can use double trailing @ to read multiple obs from one record.

 

data a;
   infile cards4 dsd dlm=';';
   input v @@;
   cards4;
1; 2; 3; 4; 5; 
;;;;
   run;

View solution in original post


All Replies
Solution
‎06-23-2016 06:53 PM
Respected Advisor
Posts: 3,799

Re: Reading raw data separated by semicolons

Posted in reply to TedShelly

You can use double trailing @ to read multiple obs from one record.

 

data a;
   infile cards4 dsd dlm=';';
   input v @@;
   cards4;
1; 2; 3; 4; 5; 
;;;;
   run;
Super User
Posts: 5,516

Re: Reading raw data separated by semicolons

Posted in reply to data_null__

That's a good approach.  You might find it necessary to include blanks as delimiters as well:

 

dlm='; '

Occasional Contributor
Posts: 10

Re: Reading raw data separated by semicolons

Posted in reply to TedShelly

This is very cool, thanks.  I had forgotten all about @@.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 247 views
  • 0 likes
  • 3 in conversation