DATA Step, Macro, Functions and more

parsing a character string into new variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 268
Accepted Solution

parsing a character string into new variables

I found the code I think I need and made a few edits but my new vars are numeric rather than char. I need char vars;

data I have:

sp

doe, john;doe, jane;doe, jack

 

data i want:

sp1                   sp2            sp3

doe, john         doe, jane   doe, jack

 

 

Code:

data betty3;
set betty2;
array parsed_vars(*) sp1-sp3;
i=1;
do while(scan(sp, i, ";") ne "");
parsed_vars(i) =scan(sp, i, ";");
i+1;
end;
run;


Accepted Solutions
Solution
‎03-30-2017 12:39 PM
PROC Star
Posts: 7,363

Re: parsing a character string into new variables

Specify that the array is character. e.g.

 

array parsed_vars(*)  $25. sp1-sp3;

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Solution
‎03-30-2017 12:39 PM
PROC Star
Posts: 7,363

Re: parsing a character string into new variables

Specify that the array is character. e.g.

 

array parsed_vars(*)  $25. sp1-sp3;

Art, CEO, AnalystFinder.com

PROC Star
Posts: 288

Re: parsing a character string into new variables

You need to specify that your array is character with a "$"

 

You also will probably want to assign some appropriate length to the variables you created or you might see truncation.

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 134 views
  • 2 likes
  • 3 in conversation